unity人物接近时触发事件或动画demo

您所在的位置:网站首页 unity中播放视频 unity人物接近时触发事件或动画demo

unity人物接近时触发事件或动画demo

2024-01-13 06:34| 来源: 网络整理| 查看: 265

定义物体GameObject o;

效果:当人物接近物体时,物体触发动画,比如位移

1.创建o的动画km和gm

2.创建空物体 Empty,大小稍微比o大一点,拖入o,用来接受触发判定,防止物体移动过后触发器跟着移动,勾选 is trigger

2.人物控制器

using System.Collections; using System.Collections.Generic; using UnityEngine; public class DoorController : MonoBehaviour { private Animation ani; void Start() { //获取子组件下的第一个组件,再获取子组件animation, //如果是获取自身组件,直接GetComponent() ani = transform.GetChild(0).GetComponent(); } private void OnTriggerEnter(Collider other){ //当物体接触到时则播放animation中的km动画 ani.Play("km"); } private void OnTriggerExit(Collider other){ //当物体接触到时则播放animation中的gm动画 ani.Play("gm"); } void Update() { } }

转载 :http://www.xook.top/post/19



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3