碰撞器,触发器

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MyCollier : MonoBehaviour {

    // Use this for initialization
    void Start () {
        
    }
    
    // Update is called once per frame
    void Update () {
        
    }
    //碰撞,这个方法unity引擎调用,碰撞触发条件:两个物体都有碰撞器,至少一个是刚体
    private void OnCollisionEnter(Collision collider){
        print (collider.collider.name);//打印与谁碰的物体
        print (collider.collider.tag);
    }
    //触发器,在碰撞器上选择 is Trigger,变成触发器,不要mesh了
    private void OnTriggerEnter(Collider other){
        print ("刚进入触发器");
    }
    private void OnTriggerStay(Collider other){
        print ("待在触发器");
    }
    private void OnTriggerExit(Collider other){
        print ("离开触发器");
    }
}

 

posted @ 2018-04-07 21:34  涂鸟少年  阅读(110)  评论(0编辑  收藏  举报