作用:检测触发OnTriggerEnter
例子:人物走过区域触发
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shoot : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider other){
print("OnTriggerEnter:" + other);
print("OnTriggerEnter:" + other.name);
print("OnTriggerEnter:" + other.tag);
}
private void OnTriggerExit(Collider other){
print("OnTriggerExit");
}
private void OnTriggerStay(Collider other){
print("OnTriggerStay");
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class shoot : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter(Collider other){
//碰到
print("OnTriggerEnter:" + other);
print("OnTriggerEnter:" + other.name);
print("OnTriggerEnter:" + other.tag);
}
private void OnTriggerExit(Collider other){
//离开
print("OnTriggerExit");
}
private void OnTriggerStay(Collider other){
//每一帧在这
print("OnTriggerStay");
}
}
用法:
1、注意文件命名,这里是shoot
2、区域的Box Collider 的Is Trigger 需要打勾,使可以进入内部
3、关掉Mesh Renderer 透明了