12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using System;
- using UnityEngine;
- /* Home场景中碗碰撞体检测和控制
- * 当狗开始喝水和吃饭动作后,狗向碗移动,检测碰撞后停止移动开始喝水吃饭动作
- * 场景中有多个狗,每次检测碰撞后反向遍历dogInScene,逐个控制移动和喝水
- */
- public class BowlColliderController : MonoBehaviour
- {
- // Start is called once before the first execution of Update after the MonoBehaviour is created
- //private GameObject bowls, bowlFood, bowlWater;
- private GameObject thisObject;
- void OnEnable()
- {
- //bowls = GameObject.Find("Bowls");
- thisObject = this.gameObject;
- //bowlFood = bowls.transform.Find("Bowl_food").gameObject;
- //bowlWater = bowls.transform.Find("Bowl_water").gameObject;
- }
- // Update is called once per frame
- //void Update()
- //{
-
- //}
- private void OnTriggerEnter(Collider other)
- {
- foreach (var dogInScene in HomeController.dogsInScene)
- {
- if (dogInScene.gameObject == other.gameObject) { // 检测哪一只doginScene发生碰撞
- if (thisObject.name == "Bowl_water")
- {
- dogInScene.isMovingToBowl = false;
- dogInScene.drinkStartTime = DateTime.Now;
- dogInScene.animator.SetTrigger("drink");
- dogInScene.animator.SetBool("isDrinking", true);
- StartCoroutine(dogInScene.DrinkAnimation());
- //dogInScene.DrinkAnimation();
- }
- if (thisObject.name == "Bowl_food")
- {
- dogInScene.isMovingToBowl = false;
- dogInScene.eatStartTime = DateTime.Now;
- dogInScene.animator.SetTrigger("eat");
- dogInScene.animator.SetBool("isEating", true);
- StartCoroutine(dogInScene.EatAnimation());
- }
- }
- }
- }
- }
|