Okay now I've got a new setup. I think this one mostly works.
Basically i have this invisible box for a game object. and my Gate is instanced inside of the Game Object.
I have two scripts, one for the gate and another for the Game Object. (I found them online, copy / paste)
The Game Object script, is supposed to activate the Gate script, and then the gate opens.
Unfortunately, the Game Object script was made for another game, and it isn't triggered on Player Enter. So that's what I'm trying to figure out how to do. I need to know how to have the Game Object enable a trigger, on Player Enter.
here's my code for the Game Object
Code:
using UnityEngine;
using System.Collections;
public class Activatable : MonoBehaviour {
public GateFunction Gate;
bool triggered = false;
bool mouseOver = false;
public bool Trigger {
get{return triggered;}
set{triggered = value;}
}
void Update()
{
if(triggered && mouseOver) //My triggered was sent from a button press of F in another script
sendTrigger(); //It just sets Trigger = true;
}
void OnMouseEnter()
{
mouseOver = true;
}
void sendTrigger()
{
Gate.Trigger = true;
triggered = false;
}
}
And here's the code for the gate...
Code:
using UnityEngine;
using System.Collections;
public class GateFunction : MonoBehaviour {
public enum GateState { open, closed, idle};
GateState currentState = GateState.idle;
public bool eventTriggered = false;
public bool Trigger {
get{return eventTriggered;}
set{eventTriggered = value;}
}
void Start()
{
StartCoroutine("CoStart");
}
IEnumerator CoStart()
{
while (true)
yield return StartCoroutine("CoUpdate");
}
IEnumerator CoUpdate()
{
yield return StartCoroutine("changeStates");
}
IEnumerator changeStates()
{
if(eventTriggered)
{
if(currentState == GateState.idle)
{
currentState = GateState.open;
}
else if(currentState == GateState.open)
{
currentState = GateState.closed;
}
else
currentState = GateState.open;
switch(currentState)
{
case GateState.idle :
animation.CrossFade("idle");
break;
case GateState.closed :
animation.CrossFade("GateClose");
yield return new WaitForSeconds(animation.GetClip("GateClose").length);
animation.CrossFade("idle");
break;
case GateState.open :
animation.CrossFade("GateOpen");
yield return new WaitForSeconds(animation.GetClip("GateOpen").length);
break;
}
}
eventTriggered = false;
yield return null;
}
}