// CHANGE STATE public void ChangeState(TowerState state, object data) { // TODO : ajouter un timer dans l'attackComponent attackComponent.Stop(); switch (state) { case TowerState.ATTACKING: attackComponent.Attack(); break; case TowerState.TARGETING: attackComponent.Stop(); attackComponent.DefineTarget((GameObject)data); break; case TowerState.IDLE: attackComponent.Stop(); attackComponent.UndefineTarget(); break; case TowerState.DESTROYED: attackComponent.Stop(); attackComponent.UndefineTarget(); break; } this.state = state; }
public void AttackTest() { HealthComponent h = new HealthComponent(100); AttackComponent a = new AttackComponent(10); a.Attack(h); Assert.AreEqual(90, h.Health, "Health after attack incorrect"); }
void Start() { GameObject unit = new GameObject("Unit"); AttackComponent attack = unit.AddComponent <AttackComponent>(); MoveComponent move = unit.AddComponent <MoveComponent>(); attack.Attack(); move.Move(); }
void Update() { if (Input.GetMouseButtonDown(0)) { startPosition = Input.mousePosition; startTime = Time.realtimeSinceStartup; isAoeNeed = true; isAttackNeed = true; } if (isAoeNeed && Time.realtimeSinceStartup - startTime > timeToAoeCast) { attackComponent.DelayAnim(); } if (isAoeNeed && Time.realtimeSinceStartup - startTime > timeToAoe) { attackComponent.AOEAttack(); isAoeNeed = false; isAttackNeed = false; } Vector3 direction = Vector3.zero; if (isAttackNeed && Input.GetMouseButtonUp(0)) { direction = startPosition - Input.mousePosition; isAoeNeed = false; } if (direction != Vector3.zero) { bool isHorizontal = Mathf.Abs(direction.x) > Mathf.Abs(direction.y); if (isHorizontal) { attackComponent.Attack(direction.x < 0 ? Direction.Right : Direction.Left); } else { attackComponent.Attack(direction.y < 0 ? Direction.Up : Direction.Down); } } }
// CHANGE STATE public void ChangeState(UnitState state, object data) { // TODO : ajouter un timer dans l'attackComponent attackComponent.Stop(); switch (state) { case UnitState.ATTACKING: movementComponent.StopMovement(); attackComponent.Attack(); break; case UnitState.TARGETING: attackComponent.Stop(); attackComponent.DefineTarget((GameObject)data); movementComponent.GoToTarget((GameObject)data); break; case UnitState.LANING: movementComponent.GoToWaypoint(); attackComponent.Stop(); attackComponent.UndefineTarget(); break; case UnitState.IDLE: movementComponent.StopMovement(); attackComponent.Stop(); attackComponent.UndefineTarget(); break; case UnitState.DEAD: movementComponent.StopMovement(); attackComponent.Stop(); attackComponent.UndefineTarget(); break; } this.state = state; }