Hello, I’m using State Patterns and its something wrong on the code.
Why the FixedUpdate(), Start(), Awake(), of StateAdormit.cs not work? I want to use a rigidbody2D.velocity there.
Where I have to put the atributes, functions, OnTriggerEnter2D, of the enemies? Now there are on Enemic.cs.
Can I fusion or delete any class?
Thanks
mainEnemic.cs
public class mainEnemic : MonoBehaviour {
private Enemic e;
void Awake () {
e = gameObject.AddComponent<Enemic>();
e.State = StateAdormit.Instance;
e.RequestAccio();
}
e.RequestAccio();
}
Enemic.cs
class Enemic : MonoBehaviour {
private State stateActual;
public Enemic(State state)
{
this.stateActual = state;
}
public State State
{
get
{
return stateActual;
}
set { stateActual = value; }
}
public void RequestAccio()
{
stateActual.Accio (this);
}
}
State.cs
interface State
{
void Accio(Enemic e);
}
StateAdormit.cs
class StateAdormit : State
{
private static StateAdormit instance;
void FixedUpdate () {
Debug.Log("moveUpdate");
}
public void Accio(Enemic e)
{
Debug.Log("action");
}
}