void Update() { if (!GetComponent <Rigidbody>()) { enabled = false; } if (myPickupObject.beingHeld) { wasBeingHeld = true; targetLocation = Vector3.zero; } else if (wasBeingHeld) { wasBeingHeld = false; GiveUp(gameObject); CreatePath(exitNode.transform.position); } foodInSight = CanSeeFood(); if ((transform.position - targetLocation).magnitude < 3f && !foodInSight) { targetLocation = Vector3.zero; } if (pathToFollow == null || pathToFollow.Count == 0) { if (targetLocation != Vector3.zero) { CreatePath(targetLocation); } else { CreatePath(exitNode.transform.position); } } if (pathToFollow.Count == 0) { CreatePath(targetLocation); } if ((exitNode.transform.position - transform.position).magnitude < 15f) { if (stolenFood != null) { stolenFood.DestroyObject(); SetStolenFood(gameObject, stolenFood.gameObject, false); } FloorTrigger.currentRats--; Destroy(gameObject); } if (stolenFood == null && targetFood == null && foodInSight && !defeated) { targetFood = foodInSight.transform; } if (targetFood && stolenFood == null && !defeated) { Vector3 zero = Vector3.zero; Vector3 a = Vector3.zero; zero += Seek(targetFood.transform.position); zero += Avoid(); a = zero; a.y = 0f; if (zero != Vector3.zero) { transform.rotation = Quaternion.LookRotation(a + transform.forward); } GetComponent <Rigidbody>().AddForce(zero.normalized * maxSpeed * 10f * Time.deltaTime); if (defeated || !targetFood || !((transform.position - targetFood.position).magnitude < 4f)) { return; } Food component = targetFood.GetComponent <Food>(); if (component.beingHeldByRat && Random.value > 0.5f) { GiveUp(component.beingHeldByRat.gameObject); } if (targetFood && component) { component.beingHeldByRat = this; SetStolenFood(gameObject, targetFood.gameObject, true); if (FloorTrigger.foodDropPosition.Contains(targetFood.gameObject)) { FloorTrigger.foodDropPosition.Remove(targetFood.gameObject); } targetLocation = Vector3.zero; CreatePath(exitNode.transform.position); targetFood = null; } } else if (pathToFollow != null && pathToFollow.Count > 0) { Vector3 position = transform.position; float x = position.x; Vector3 position2 = transform.position; Vector2 a2 = new Vector2(x, position2.z); Vector3 position3 = pathToFollow[0].transform.position; float x2 = position3.x; Vector3 position4 = pathToFollow[0].transform.position; Vector2 b = new Vector2(x2, position4.z); float magnitude = (a2 - b).magnitude; if (magnitude < 4f) { pathToFollow.RemoveAt(0); } Vector3 zero2 = Vector3.zero; Vector3 a3 = Vector3.zero; if (pathToFollow.Count > 0) { zero2 += Seek(pathToFollow[0].transform.position); zero2 += Avoid(); a3 = zero2; a3.y = 0f; } else { zero2 += Seek(targetLocation); zero2 += Avoid(); a3 = zero2; a3.y = 0f; } if (zero2 != Vector3.zero) { transform.rotation = Quaternion.LookRotation(a3 + transform.forward); } GetComponent <Rigidbody>().AddForce(zero2.normalized * maxSpeed * 10f * Time.deltaTime); } if (stolenFood && stolenFood.transform.parent != transform) { SetStolenFood(gameObject, stolenFood.gameObject, false); Debug.Log("Test!"); } }