// Update is called once per frame void Update() { if (waypoints == null || Global.CurrentGameState != Global.GameState.Game) { return; } //Remove modification after it has expired if (CurrentMovement != EnemyMovementSpeed.Normal && Time.time >= endModificationTime) { CurrentMovement = EnemyMovementSpeed.Normal; GetComponent <Enemy>().ChangeColor(Enemy.ColorState.Normal); } //Speed mods from tower SpeedMod = SpeedMods[(int)CurrentMovement]; Vector3 currentPos = nextPoint - transform.position; if (currentPos.magnitude < DistanceFromWaypoint) { this.transform.position = new Vector3(nextPoint.x, nextPoint.y, this.transform.position.z); SetCurrentWaypoint(direction); } Vector3 moveDelta = (speed * SpeedMod * mEggSpeedMod * Time.smoothDeltaTime) * transform.up; transform.position += moveDelta; DistanceTraveled += moveDelta.magnitude; }
// Use this for initialization void Start() { DistanceFromWaypoint = 0.035f; global = GameObject.Find("Global").GetComponent <Global>(); CurrentMovement = EnemyMovementSpeed.Normal; SpeedMod = SpeedMods[(int)CurrentMovement]; listPos = direction = 1; waypoints = global.CurrentMap.Waypoints; nextPoint = waypoints[listPos]; transform.up = nextPoint - transform.position; }
/// <summary> /// Modify the speed of enemy /// </summary> /// <param name="mod">Type of modification to be applied</param> /// <param name="duration">Lenght in seconds the modification should last</param> public void UpdateSpeedMod(EnemyMovementSpeed mod, float duration) { if (mod == EnemyMovementSpeed.Slow) { GetComponent <Enemy>().ChangeColor(Enemy.ColorState.Slow); } CurrentMovement = mod; SpeedMod = SpeedMods[(int)CurrentMovement]; endModificationTime = Time.time + duration; }