- Home /
[Closed] Open/Close Chest with delay...
Hello! In the scene I have an object(chest) which should be opened by clicking the mouse. (Of course I have all the animations and Box Collider) 
But! I need to chest could not be opened and closed to everyone mouse click. Between animations should be delay for 2 seconds. I have a C# script, where a chest can have 3 states (Open, Close and Inbetween). At start chest have state "Close". When i click on it, state chenge to "Inbetween" but then nothing happens although the state must change On "Open".
Script
using UnityEngine;
using System.Collections;
public class Chest : MonoBehaviour {
public enum State {
open,
close,
inbetween
}
public State state;
// Use this for initialization
void Start () {
state = Chest.State.close;
}
// Update is called once per frame
void Update () {
}
public void OnMouseEnter() {
Debug.Log("Enter");
}
public void OnMouseExit() {
Debug.Log("Exit");
}
public void OnMouseUp() {
Debug.Log("Up");
switch(state){
case State.close:
state = Chest.State.inbetween;
StartCoroutine("Open");
break;
case State.open:
state = Chest.State.inbetween;
StartCoroutine("Close");
break;
}
}
private IEnumerable Open() {
animation.Play("open");
yield return new WaitForSeconds(animation["open"].length);
state = Chest.State.open;
}
private IEnumerable Close() {
animation.Play("close");
yield return new WaitForSeconds(animation["close"].length);
state = Chest.State.close;
}
}
How can I fix it? Thanks in advance
P.S. Sorry for my english
i believe you want to use IEnumerator not IEnumerable for your coroutine return values.
Yes, IEnumerator. Refer to http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.StartCoroutine.html
Your answer
Follow this Question
Related Questions
Sniper zooming (toggle) 2 Answers
delay first spawn 2 Answers
How to delay a shot. 4 Answers
How to make my espawn delay trigger to work more than once. 2 Answers
Delay between animations 1 Answer