using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class playContorller : MonoBehaviour
{
public GameObject play;
public GameObject door;
void Start()
{
play = GetComponent<GameObject>();
door = GameObject.Find("door");
}
// Update is called once per frame
void Update()
{
//获取水平轴
float horizontal = Input.GetAxis("Horizontal");
//垂直轴
float vertical = Input.GetAxis("Vertical");
Vector3 dir = new Vector3(horizontal, 0, vertical);
transform.Translate(dir * 2 * Time.deltaTime);
}
private void OnTriggerEnter(Collider other)
{
Debug.Log("触发器");
door.active = false;
}
private void OnTriggerStay(Collider other)
{
Debug.Log("持续触发");
}
private void OnTriggerExit(Collider other)
{
Debug.Log("触发结束");
door.active = true;
}
}
unity触发器代码demo
于 2023-02-24 14:32:02 首次发布