Activating a gameobject from a script attached to a different gameobject.
I have a gameObject with this script attached to it:
void Start () {
gameObject.SetActive (false);
}
There's a different gameObject that has the following:
public GameObject SuperJumpItem;
public int count;
void OnTriggerEnter(Collider other){
if (other.gameObject.CompareTag("Something Else")){
other.gameObject.SetActive (false);
count = count + 1;
if (count >= 12){
SuperJumpItem.SetActive (true);
}
}
Basically, the code states that once the "different gameObject" collides with its 12th "Something Else," the first gameObject would be set to active, Unfortunately, this doesn't work. I've tried setting "count" to 0. I tried moving the if statement to an Update function. No luck. Any assistance would be greatly appreciated.
Is the object present in SuperJumpItem or is that a null value. Put some Debug.Log functions to see how your code reacts and if you even reach the code you try to execute.
Answer by ShockSword · Nov 26, 2017 at 07:50 AM
Welp it turns out I didn't assign the gameObject to the variable.
Your answer
Follow this Question
Related Questions
how to move a gameobject based on a dice roll 1 Answer
Help! Script won't work. 1 Answer
The score/count only goes to 1 and not further. 0 Answers
Template object and script,GameObject scripts duplicated from a template game object 0 Answers
New Vector2 won't take effect when called from another script in the same GameObject. 0 Answers