Search Unity

My if will run even and ignore the statement

Discussion in 'Scripting' started by TheExpensiveDev, Mar 5, 2019.

  1. TheExpensiveDev

    TheExpensiveDev

    Joined:
    Mar 5, 2019
    Posts:
    2
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class collect : MonoBehaviour
    6. {
    7.  
    8.     public GameObject mons;
    9.     public MoneyHandler monhand;
    10.     public bool stuff = false;
    11.  
    12.  
    13.     private void Start()
    14.     {
    15.         monhand = FindObjectOfType<MoneyHandler>();
    16.      
    17.  
    18.     }
    19.  
    20.     private void OnMouseDown()
    21.     {
    22.         if (stuff == false)
    23.         {
    24.          
    25.             stuff = true;
    26.             monhand.addMoney(5);
    27.          
    28.         }
    29.     }
    30.  
    31. }
    32.  
    btw my gameobject is in an animation in this time
     
    Last edited: Mar 5, 2019
  2. NicBischoff

    NicBischoff

    Joined:
    Mar 19, 2014
    Posts:
    204
    Your bool is probably true. Make it private and test.
     
  3. TheExpensiveDev

    TheExpensiveDev

    Joined:
    Mar 5, 2019
    Posts:
    2
    thanks, but i used something else :)