Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class FoodEat : MonoBehaviour
  6. {
  7. public GameObject FoodGO;
  8. public Rigidbody FoodRB;
  9.  
  10. private void OnTriggerEnter(Collider Creature)
  11. {
  12. Destroy(FoodGO);
  13. }
  14.  
  15. void Start()
  16. {
  17. FoodRB = GetComponent<Rigidbody>();
  18. FoodGO = FoodRB.gameObject;
  19. }
  20.  
  21. void Update()
  22. {
  23. Rigidbody[] allRigidBodies = (Rigidbody[])FindObjectsOfType(typeof(Rigidbody));
  24.  
  25. foreach (Rigidbody body in allRigidBodies)
  26. {
  27. if (body.gameObject.layer == 10)
  28. {
  29. OnTriggerEnter(body.gameObject.GetComponent<CapsuleCollider>());
  30. }
  31.  
  32. }
  33.  
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement