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. Dismiss Notice

Question Bool wont turn to false

Discussion in '2D' started by so_1899, Mar 26, 2021.

  1. so_1899

    so_1899

    Joined:
    Mar 19, 2021
    Posts:
    11
    Hello Good evening ,
    im working on a project which containes a player who throws a bomb with 2 differents scripts so here is my example :

    the problem Is the boolean Isdropped turn always true & wont turn false again :(

    Script A
    Code (CSharp):
    1. public class Bombscript : MonoBehaviour
    2. {
    3.        public BOMBDROPPOINT other;
    4.  
    5.    
    6.     void Start()
    7.     {
    8.        
    9.     }
    10.  
    11.  
    12.     void Update()
    13.     {
    14.  
    15.      
    16.         if (Input.GetButtonDown("Fire1"))
    17.         {
    18.             Explode();
    19.             other.Isdropped = false;
    20.         }
    21.  
    22.     }
    23.    
    24.     public void Explode()
    25.  
    26.  
    and the Script B who contains the droppoint (Player)

    Code (CSharp):
    1. public class BOMBDROPPOINT : MonoBehaviour
    2. {
    3. public bool Isdropped = false ;
    4. public Bombscript other;
    5. private void Start()
    6.     {
    7. }
    8.  
    9.     void Update()
    10.     {
    11. if (Input.GetButtonDown("Fire1") && Isdropped == false)
    12.             {
    13.                
    14.                     Drop();
    15.                     Isdropped = true;
    16.                    
    17.             }
    18.         }
    19.  
    20.  
    21.  
    PS : i did it on purpose when binding Fire 1 for 2 actions (thats my goal)
    thanks
     
  2. rarac

    rarac

    Joined:
    Feb 14, 2021
    Posts:
    570
    change this

    Code (CSharp):
    1.       if (Input.GetButtonDown("Fire1") && other.Isdropped == true )
    2.         {
    3.             Explode();
    4.             other.Isdropped = false;
    5.         }
    6.  
     
  3. so_1899

    so_1899

    Joined:
    Mar 19, 2021
    Posts:
    11
    changed it but the bomb now isnt exploding and the bool still true