public void SetDroneTargetTest() { GameObject go = new GameObject("Turret"); Turret t = go.AddComponent<Turret>(); TAim tAim = go.AddComponent<TempClass>(); t.aim = tAim; t.target = tAim.FindTarget(); Assert.AreNotEqual(null, t.target); }
// Update is called once per frame protected void Update() { if (aim != null) // Triggered if users completed their code { target = aim.FindTarget(); } if (target != null) // If there is a target { // Calculate rotation Vector3 targetRotation = target.transform.position - turret.position; targetRotation.y = 0f; turret.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(targetRotation), 1f); // Rotate towards a target target.TakeDamage(dmg); // Deal damage // Show line from a turret to the enemy line.enabled = true; laserBeamStart.Play(); // Play particle system line.SetPosition(0, laserStart.position); line.SetPosition(1, target.transform.position); // Set texts color based on in-game events lookingText.color = new Color(lookingText.color.r, lookingText.color.g, lookingText.color.b, 0.2f); foundText.color = new Color(foundText.color.r, foundText.color.g, foundText.color.b, 1.0f); } else { // Disable a line line.enabled = false; laserBeamStart.Stop(); // Stop particle system // Rotate around y axis turret.rotation *= Quaternion.AngleAxis(Time.deltaTime * rotationSpeed, Vector3.up); // Set texts color based on in-game events lookingText.color = new Color(lookingText.color.r, lookingText.color.g, lookingText.color.b, 1.0f); foundText.color = new Color(foundText.color.r, foundText.color.g, foundText.color.b, 0.2f); } }