Basically, when I hover over the collider it’ll call exit and enter once. I can click on the ‘LootChest’ to open it, but it’s unreliable. I have to click all over the hitbox and it seems totally random. I tried placing mesh and collider in empty scene with same result. Tried many sizes of box collider as well. Code is below. Am I missing something?
using UnityEngine;
using System.Collections;
public class LootChest : MonoBehaviour {
public enum State
{
Open,
Changing,
Closed
}
public State _chestState;
// Use this for initialization
void Start () {
_chestState = LootChest.State.Closed;
}
// Update is called once per frame
void Update () {
}
public void OnMouseEnter()
{
Debug.LogWarning ("Enter");
}
public void OnMouseExit()
{
Debug.Log ("Exit");
}
public void OnMouseUp()
{
Debug.Log ("Up");
switch(_chestState){
case LootChest.State.Open:
_chestState = LootChest.State.Changing;
StartCoroutine("Close");
break;
case LootChest.State.Closed:
_chestState = LootChest.State.Changing;
StartCoroutine("Open");
break;
}
}
private IEnumerator Open()
{
animation.Play("GoodOpen");
yield return new WaitForSeconds(animation["GoodOpen"].length);
_chestState = LootChest.State.Open;
}
private IEnumerator Close()
{
animation.Play("GoodClose");
yield return new WaitForSeconds(animation["GoodClose"].length);
_chestState = LootChest.State.Closed;
}
}