PlayerColliderController.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using UnityEngine;
  3. /* 用于检测在交互场景开始时候狗向玩家走过来时候,玩家与狗的碰撞检测
  4. * 待删除,因为狗可以用距离控制
  5. */
  6. public class PlayerColliderController : MonoBehaviour
  7. {
  8. private GameObject thisObject;
  9. // Start is called once before the first execution of Update after the MonoBehaviour is created
  10. void Start()
  11. {
  12. thisObject = this.gameObject;
  13. }
  14. // Update is called once per frame
  15. //void Update()
  16. //{
  17. //}
  18. private void OnTriggerEnter(Collider other)
  19. {
  20. foreach (var dogInScene in HomeController.dogsInScene)
  21. {
  22. if (dogInScene.gameObject == other.gameObject)
  23. { // 检测哪一只doginScene发生碰撞
  24. if (thisObject.name == "Bowl_water")
  25. {
  26. dogInScene.isMovingToBowl = false;
  27. dogInScene.drinkStartTime = DateTime.Now;
  28. dogInScene.animator.SetTrigger("drink");
  29. dogInScene.animator.SetBool("isDrinking", true);
  30. StartCoroutine(dogInScene.DrinkAnimation());
  31. //dogInScene.DrinkAnimation();
  32. }
  33. if (thisObject.name == "Bowl_food")
  34. {
  35. dogInScene.isMovingToBowl = false;
  36. dogInScene.eatStartTime = DateTime.Now;
  37. dogInScene.animator.SetTrigger("eat");
  38. dogInScene.animator.SetBool("isEating", true);
  39. StartCoroutine(dogInScene.EatAnimation());
  40. }
  41. }
  42. }
  43. }
  44. }