Hey! I am trying to create a mana-pickup item. Which will dissapear if a player touches it and then appear and the same place 2 seconds later.
When I run the code, everything seems to work, except it doesn’t finish it: the component gets diabled and disappears, but doesn’t appear back in 2 seconds, NOR does it print anything. Could you please help? Thank you very much!
Here’s the code:
using UnityEngine;
using System.Collections;
public class manaboxscript : MonoBehaviour {
public GameObject enteredgameobject;
public imagescript linkvariable;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other)
{
enteredgameobject = other.gameObject;
linkvariable = enteredgameobject.GetComponent<imagescript> ();
StartCoroutine(WaitAndPrint(2.0F));
}
IEnumerator WaitAndPrint(float waitTime) {
gameObject.SetActive (false);
yield return new WaitForSeconds(waitTime);
print(waitTime);
print("WaitAndPrint " + Time.time);
gameObject.SetActive (true);
}
}