Reall noob question

i want to trigger animations cant seem to find error glass one does not seem to work can somebody point out what am i doing wrong

using UnityEngine;
using System.Collections;

public class doorwala : MonoBehaviour {
public Animator ani;
public int i;

// Use this for initqialization
void Start () {

}

void OnTriggerEnter (Collider other){
if (other.gameObject.tag == “player”) {
if (i < 5) {
ani = GameObject.FindWithTag (“trigger”).GetComponent ();

ani.SetInteger (“b”, i);
} else {
ani = GameObject.FindWithTag (“glass”).GetComponent ();

ani.SetInteger (“test”, i);
}
}

}

/* void OnTriggerExit (Collider other){
if (other.gameObject.tag == “Player”) {
i = 2;
ani.SetInteger (“b”, i);
}
}*/
// Update is called once per frame
void Update () {

}
}

you don’t appear to ever set “i” to be more than 5, so the else clause is never reached…

Mmhh… The code that handles the variable i would be useful to determine the problem. However, you may try to do something to correct the bug:

  • Put a Debug.Log("Glass") in the else branch in order to understand if it's executed.
  • You can try to use the technique in 1 outputting the value of ani (try to see if it's null or not)
  • If you're using MonoDevelop (or VS with VS tools), you may try to start debugging to inspect the problem

Finally, I’d advise you not to use GameObject.FindWithTag if it’s not necessary: if the GameObject you want to look for is present in the scene at the time you’re instantiating the GameObject that has this component, you can use a global variable to hold it and get a faster access to it.

Hope this helps…

Jymmy097

i have tried Debug.log but even if the condition is true it never executes the animation clip

2606568--182695--upload_2016-4-22_23-31-12.png

2606568--182691--upload_2016-4-22_23-25-15.png2606568--182692--upload_2016-4-22_23-25-54.png