using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class OpenCloseDoor : MonoBehaviour {
private Transform m_transform;
// Use this for initialization
void Start () {
m_transform=GameObject.Find("DoorFather").GetComponent<Transform>();
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other) {
if (other.gameObject.name == "Player") {
m_transform.Rotate(Vector3.up * 100);
}
}
void OnTriggerExit(Collider other) {
if (other.gameObject.name == "Player") {
m_transform.Rotate(Vector3.down * 100);
}
}
}
Unity3D学习记录——触发器开关门
最新推荐文章于 2024-04-25 19:39:53 发布
本文介绍了一个简单的Unity脚本,该脚本使游戏中的门在玩家接近时打开,并在玩家离开时关闭。通过使用Collider触发器,当名为Player的游戏对象进入触发区域时,门将绕其上轴旋转100度;当玩家离开触发区域时,门则恢复原位。
1万+

被折叠的 条评论
为什么被折叠?



