public override void Enter(StateMachine obj) { AgentState s = obj.controller.GetState(); GameObject t = obj.FindClosestEnemy(); obj.controller.SetMovementTarget(t.transform); Debug.Log("Enter " + this.GetType().Name + " : " + obj.agent.name + " --> " + obj.controller.GetState().Moving); //obj.agent.animation.CrossFade("walk"); }
public override void Execute(StateMachine obj) { AgentState s = obj.controller.GetState(); // s.AttackTarget = GameObject.Find("AttTarget"); GameObject t = obj.FindClosestEnemy(); float d = Vector3.Distance(obj.agent.transform.position, t.transform.position); Debug.Log(obj.agent.name + ":: " + d+" to "+t.transform.position); if (d > 20) { obj.ChangeState(RoamState.GetInstance()); } }
public override void Execute(StateMachine obj) { GameObject t = obj.FindClosestEnemy(); float d = Vector3.Distance(obj.agent.transform.position, t.transform.position); if (obj.controller.GetState().AttackTarget == null || obj.controller.GetState().CurrentAttackType == -1) { obj.controller.SetAttack(AgentAttack.MEDIUM_RANGE); obj.controller.SetAttackTarget(t); } if (d < obj.controller.GetState().attackTypes[obj.controller.GetState().CurrentAttackType].range/2.0f) { obj.controller.GetState().Moving = false; } else if (d>30) { obj.controller.SetAttackTarget(null); obj.controller.SetAttack(-1); obj.ChangeState(InitialState.GetInstance()); } }
public override void Execute(StateMachine obj) { AgentState s = obj.controller.GetState(); if (s.CurrentPath != null && s.CurrentPath.IsDone()) { obj.controller.GetState().Moving = true; } // s.AttackTarget = GameObject.Find("AttTarget"); GameObject t = obj.FindClosestEnemy(); obj.controller.SetMovementTarget(t.transform); float d = Vector3.Distance(obj.agent.transform.position, t.transform.position); Debug.Log(obj.agent.name + ":: " + d+" to "+t.transform.position); if (d <= 20 ) { int layer = 1 << 9; if (!Physics.Raycast(obj.agent.transform.position, (t.transform.position-obj.agent.transform.position)/d,d,layer)) obj.ChangeState(ChaseState.GetInstance()); } }