// Moves the object on the X and Z axis. public void Move(float horizontal, float vertical) { float x = horizontal * speed * time.GetTime(); float z = vertical * speed * time.GetTime(); Vector3 newPosition = new Vector3(x, 0, z); self.position += newPosition; }
// Deactivate the explosion when its reached its lifetime. void Update() { lifeTime -= unityTime.GetTime(); if (lifeTime < 0) { Deactivate(); } }
// Moves the target marker around the Player, restricted by a maximum range. public void Move(float horizontal, float vertical) { float x = horizontal * speed * time.GetTime(); float z = vertical * speed * time.GetTime(); Vector3 newTargetLocation = self.position + new Vector3(x, 0, z); // Get distance from center to target. Vector3 toTarget = newTargetLocation - origin; float distance = toTarget.sqrMagnitude; // If distance is greater than the range limit, then keep it within bounds. if (distance > rangeCheck) { newTargetLocation = origin + (toTarget.normalized * rangeLimit); } self.position = newTargetLocation; }
// Update is called once per frame void Update() { timeElapsed += unityTime.GetTime(); if (timeElapsed > timeToSpawn) { enemySpawner.Spawn(); // Get ready for the next spawn. timeElapsed = 0; timeToSpawn = Random.Range(0, maxSpawnTime); } }
public void Initialize_Movement() { var go = new GameObject(); objectTransform = go.transform; objectTransform.position = Vector3.zero; var speed = 1f; IUnityTime timeInformation = Substitute.For <IUnityTime>(); timeInformation.GetTime().Returns(1f); basicMovement = new Movement(objectTransform, speed, timeInformation); }
public void InitializeTargetMovement() { var go = new GameObject(); mover = go.transform; mover.position = Vector3.zero; origin = Vector3.zero; rangeLimit = 2f; var speed = 1f; IUnityTime timeInformation = Substitute.For <IUnityTime>(); timeInformation.GetTime().Returns(1f); targetMovement = new TargetMovement(mover, origin, speed, rangeLimit, timeInformation); }