// Update is called once per frame void Update() { //Finds the script 'ZombieVision' being use on the game object cone GameObject Cone = GameObject.Find("Cone8"); ZombieVision VisionScript = Cone.GetComponent <ZombieVision>(); GameObject Zombie = GameObject.Find("Zombie8"); Health HealthScript = Zombie.GetComponent <Health>(); if ((target != null) && ((/*Finds the variable 'detected' in the ZombieVision script and checks if true, or for 'TakenDamage'*/ VisionScript.detected == true) || (HealthScript.TakenDamage == true))) { Vector3 currentPosition = transform.position; Vector3 targetPosition = target.position; float currentSpeed = speed * 0.01f; transform.position = Vector3.MoveTowards(currentPosition, targetPosition, currentSpeed); } }
// Update is called once per frame private void Update() { GameObject Cone = GameObject.Find("Cone"); ZombieVision VisionScript = Cone.GetComponent <ZombieVision>(); GameObject Zombie = GameObject.Find("Zombie"); Health HealthScript = Zombie.GetComponent <Health>(); if ((target != null) && ((VisionScript.detected == true) || (HealthScript.TakenDamage == true))) { Vector3 currentPosition = transform.position; Quaternion currentRotation = transform.rotation; Vector3 targetPosition = target.position; Vector3 difference = targetPosition - currentPosition; float angleZ = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg; Vector3 rotationInDegrees = new Vector3(); rotationInDegrees.x = 0; rotationInDegrees.y = 0; rotationInDegrees.z = angleZ + adjustmentAngle; Quaternion rotationInRadians = Quaternion.Euler(rotationInDegrees); float rotationSpeed = Time.deltaTime * smoothing; transform.rotation = Quaternion.Lerp(currentRotation, rotationInRadians, rotationSpeed); } }