Hi, i am learning C#, and i´m making a game with some friends.
I´m having problems with yield. What i´m trying to do is that when you touch a trigger, after 2 seconds the gameobject gets disabled. And I want the gameobject be enabled again after another 2 seconds.
I tried to write two yield return new Waitforseconds but the second one doesn´t seems to work, so I decided to create a bool and when that bool is true, in FixedUpdate function, there is a float, and finally, when that float gets X number the gameobjects ges enabled again.
There is my code:
using UnityEngine;
using System.Collections;
public class nube_real : MonoBehaviour
{
public bool hideNR = false;
public float tiempoOculta = 0;
public ParticleSystem nubeR;
IEnumerator OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "pj")
{
yield return new WaitForSeconds(2);
gameObject.SetActive(false);
nubeR.Play();
hideNR = true;
}
}
void FixedUpdate()
{
if (hideNR == true)
{
tiempoOculta ++;
}
if (tiempoOculta >=100)
{
Debug.Log("Hola");
gameObject.SetActive(true);
hideNR = false;
}
}
}
I also tried this, but like I said before, the second yield doesn´t seems to work.
public bool hideNR = false;
public ParticleSystem nubeR;
IEnumerator OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "pj")
{
yield return new WaitForSeconds(2);
gameObject.SetActive(false);
nubeR.Play();
yield return new WaitForSeconds(2);
gameObject.SetActive(true);
}
}
Thank you and sorry for my English.