void EnterState(GameState state) { switch (state) { case GameState.Prepare: StartCoroutine(ComponentTools.SetWaitTime(1f, () => { Game_State = GameState.Begin; })); break; case GameState.Begin: GameObject go = GameObject.Find("jidiposwofang"); Framework.SendEvent(ThisGameEvent.CreateUnit, new GenerateUnitInfo(5, Camp.PlayerOne, go.transform.position)); go = GameObject.Find("birthpos1"); Framework.SendEvent(ThisGameEvent.CreateUnit, new GenerateUnitInfo(1, Camp.PlayerOne, go.transform.position)); // go = GameObject.Find("jidiposdifang"); Framework.SendEvent(ThisGameEvent.CreateUnit, new GenerateUnitInfo(6, Camp.PlayerTwo, go.transform.position)); go = GameObject.Find("birthpos2"); Framework.SendEvent(ThisGameEvent.CreateUnit, new GenerateUnitInfo(1, Camp.PlayerTwo, go.transform.position)); m_GameState = GameState.Playing; break; } }
void FindTarget() { if (pathingTarget == null) { pathingTarget = BattleManager.Instance.GetPathingTarget(unit.m_EnemyCamp, unit.m_UnitInfo); } if (pathingTarget != null && m_bFindPath) { if (m_bFindPath) { StartCoroutine(ComponentTools.SetWaitTime(0.3f, () => { m_bFindPath = true; })); } path = NavMesh2D.GetSmoothedPath(transform.position, pathingTarget.transform.position); m_bFindPath = false; //if (pathingTarget.transform.position != lastTargetPos) //{ // path = NavMesh2D.GetSmoothedPath(transform.position, pathingTarget.transform.position); // lastTargetPos = pathingTarget.transform.position; //} } if (path != null && path.Count != 0) { transform.position = Vector2.MoveTowards(transform.position, path[0], unit.m_UnitInfo.speed * Time.deltaTime); float fDis = Vector2.Distance(transform.position, path[0]); if (fDis < 0.01f) { path.RemoveAt(0); } //if (path.Count == 1) //{ // if (Mathf.Abs(transform.position.x - path[0].x) < 0.1f) // { // path.RemoveAt(0); // } //} //else //{ // float fDis = Vector2.Distance(transform.position, path[0]); // if (fDis < 0.1f) // { // path.RemoveAt(0); // } //} } }
protected override void EnterState(UnitState state) { switch (state) { case UnitState.Birth: StartCoroutine(ComponentTools.SetWaitTime(1f, () => { currentState = UnitState.Normal; })); break; case UnitState.Normal: break; case UnitState.Die: break; default: break; } }