Jorvan
1
Here is what i got:
using UnityEngine;
using System.Collections;
public class Compuerta : MonoBehaviour {
public int lobajo = -10;
public GameObject player;
public GameObject compuertilla;
private Animator comp;
void Start () {
comp = gameObject.GetComponentInChildren<Animator>();
}
void Update () {
if (player.transform.position.y < lobajo) {
comp.SetInteger ("Autocom", 1);
compuertilla.GetComponent<MeshCollider> ().enabled = false;
}
else if (player.transform.position.y > lobajo) {
**//Here is where I want it to wait for 2 seconds**
comp.SetInteger ("Autocom", 0);
compuertilla.GetComponent<MeshCollider> ().enabled = true;
}
}
}
I have searched, but nobody answer it for an update, can someone help me pls?
Arkaid
2
Use Coroutines!
public class Compuerta : MonoBehaviour
{
public int lobajo = -10;
public GameObject player;
public GameObject compuertilla;
private Animator comp;
void Start ()
{
comp = gameObject.GetComponentInChildren<Animator>();
StartCoroutine(UpdateCoroutine());
}
IEnumerator UpdateCoroutine()
{
while(true)
{
if (player.transform.position.y < lobajo)
{
comp.SetInteger ("Autocom", 1);
compuertilla.GetComponent<MeshCollider> ().enabled = false;
}
else if (player.transform.position.y > lobajo)
{
**//Here is where I want it to wait for 2 seconds**
yield return new WaitForSeconds(2);
comp.SetInteger ("Autocom", 0);
compuertilla.GetComponent<MeshCollider> ().enabled = true;
}
yield return null;
}
}
}
system
3
Ok You can by using time vairable in Update :
public int lobajo = -10;
public GameObject player;
public GameObject compuertilla;
private Animator comp;
float timeCount;
public float delayTime = 2.0f;
void OnEnable ()
{
timeCount = 0;
}
void Start ()
{
comp = gameObject.GetComponentInChildren<Animator> ();
}
void Update ()
{
if (timeCount < delayTime) {
timeCount += Time.deltaTime;
return;
}
if (player.transform.position.y < lobajo) {
comp.SetInteger ("Autocom", 1);
compuertilla.GetComponent<MeshCollider> ().enabled = false;
} else if (player.transform.position.y > lobajo) {
**//Here is where I want it to wait for 2 seconds**
comp.SetInteger ("Autocom", 0);
compuertilla.GetComponent<MeshCollider> ().enabled = true;
}
}