The title says it all. im trying to animate my cursor by hiding it, instantiating an animation in its place, wait until the animation is over, then resume. I am not using any gui components so gui methods will not work in this particular case. Heres my code
using UnityEngine;
using System.Collections;
public class changeCursor : MonoBehaviour {
double t;
float tf;
public GameObject cursorAnimation;
private GameObject cursorInstance;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void wait(float x){
t = Time.time;
tf = Time.time + x;
while(t < tf){
t = t + 0.001;
}
}
public void playAnimation(){
Debug.Log ("RUNANIMATION");
cursorInstance = (GameObject)Instantiate (cursorAnimation, transform.position, transform.rotation) as GameObject;
cursorInstance.transform.SetParent (transform);
}
public void hideCursor(){
gameObject.GetComponent<Renderer> ().enabled = false;
gameObject.GetComponent<Renderer> ().enabled = false;
if (gameObject.transform.GetChild (1).name.Contains ("cursor")) {
Debug.Log("Destroyed!!!!!!!!!!!!!!!!!!!!");
Destroy (gameObject.transform.GetChild (1).gameObject);
}
}
public void goBackNormal(){
Debug.Log ("BACKKKKKKKKKKKKK");
gameObject.GetComponent<Renderer> ().enabled = true;
}
}
and then the methods are being called in this order from the other code
transform.parent.GetComponent<changeCursor>().playAnimation();
transform.parent.GetComponent<changeCursor>().hideCursor();
transform.parent.GetComponent<changeCursor>().wait(2);
transform.parent.GetComponent<changeCursor>().goBackNormal();
Debug.Log("This should Work!");
all of the debug.logs get called, ive tried moving the if statement that destroys the animation around in the other methods, but none of them seem to work. in its curent state, the canimation doesnt get instantiated at all (or is being destroyed before the wait funtion is called. when i had it (it think in the goBackNormal function), the animation would instantiate, but never be destoryed. Id also like to add, the wait method does not seem to be doing anything. does anybody have any ideas?