Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why is this bool not changing to True?

Discussion in 'Scripting' started by Unlimited_Energy, Oct 20, 2017.

  1. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    Prints message fine and everything works, no error its just the bool is not changing. It's like its completely ignoring it.

    void OnCollisionEnter(Collision other)
    {
    //if (RunCollisionOnce == true)



    if (RunCollisionOnce == true && other.gameObject.name == "ninjato" || other.gameObject.tag == "Weapon")
    {
    RunCollisionOnce = false;
    print("should have checked Collision Bool");
    if (strainAtributes.qualityScore <= 19)
    {
    star1.sprite = starGold;
    }
    if (strainAtributes.qualityScore >= 20 && strainAtributes.qualityScore <= 29)
    {
    star2.sprite = starGold;
    }
    else if (strainAtributes.qualityScore >= 30)
    {
    star3.sprite = starGold;
    achievementcontrol.PlantsAtAAA += 1;
    }
    else
    {

    }
    }
    else
    {
    }
    }
     
  2. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Unlimited_Energy likes this.
  3. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    but it is true and everything within that if statement runs except the bool being switched to false...... it's not that the if statement does not work, its just the bool not being switched.
     
  4. johne5

    johne5

    Joined:
    Dec 4, 2011
    Posts:
    1,133
    what code is changing it to true, can you show us that?
     
    Unlimited_Energy likes this.
  5. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    just realized that its a public bool set to true by default but when the objects are instantiated as clones the bool is not true at all on it. it is set to false. What could possibly cause it to not be set to true? there is nothing else that access this bool and the only thing that can turn it off is when the object marked as weapon by tag or named ninjato comes into contact with it... I have made sure there is nothing colliding with it with either of these tagged or named. every instantiated clone has its bool to false...
     
  6. Unlimited_Energy

    Unlimited_Energy

    Joined:
    Jul 10, 2014
    Posts:
    469
    Ahhh so I figured it out. I have the prefabs in my scene heiarchy. I edited them with something else and saved them. At teh time they were saved the public bool was set to false and I hit apply changed to prefab. I then saved the script that is on that prefab with the bool set to true. So the prefab options override the script, EVEN if i make changes to the main script on it after i hit apply prefab changes?