Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

[SOLVED]if int=0 , setbool PLEASE HELP TO BEGINNER (HEALTH)

Discussion in 'Scripting' started by latasever8, Apr 26, 2020.

  1. latasever8

    latasever8

    Joined:
    Jun 22, 2019
    Posts:
    16
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class ağaç : MonoBehaviour {
    6.     public int ağacan = 100;
    7.     public int can;
    8.     public Animator düşüş;
    9.  
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.  
    14.         can = ağacan;
    15.        
    16.     }
    17.    
    18.  
    19.         void OnTriggerEnter(Collider other)
    20.     {
    21.         if (other.gameObject.tag == "balta")
    22.         {
    23.             TakeDamage (20);
    24.         }
    25.  
    26.     }
    27.  
    28.         void TakeDamage(int damage)
    29.         {
    30.          can -= damage;
    31.         }
    32.  
    33.  
    34.     void Update () {
    35.  
    36.         if    can = 0;
    37.  
    38.             {
    39.         düşüş.SetBool ("düşüş" , true);
    40.     }
    41.            
    42.     }
    43. }
    44.  
    45.  


    in the last line, I'm trying to make -> if "can" = 0, setbool=true
    but its not working please help
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    I'll bet that "can" is likely going below 0 if it's at a low-enough value when "TakeDamage" is called.
    Try changing the condition to this:
    Code (CSharp):
    1. void TakeDamage(float damage) {
    2.    can -= damage;
    3.  
    4.    //No need to be checking this condition every frame in Update.
    5.    if(can <= 0) {
    6.       düşüş.SetBool ("düşüş" , true);
    7.    }
    8. }
    Edit:
    Also, I just noticed your if-statement wouldn't even compile, and you were using "= 0" instead of "== 0".
    That would be the main reason for this not working.

    if-statements follow this syntax:
    Code (CSharp):
    1. if(condition) {
    2.    //execution
    3. }
    "=" assigns the value.
    "==" compares the value.
     
    Last edited: Apr 26, 2020
    latasever8 likes this.
  3. latasever8

    latasever8

    Joined:
    Jun 22, 2019
    Posts:
    16
    you're GREAT
     
  4. latasever8

    latasever8

    Joined:
    Jun 22, 2019
    Posts:
    16
    thanks again