zoukankan      html  css  js  c++  java
  • Unity3d 碰撞检测

    using UnityEngine;
    using System.Collections;
    
    public class hitCheck : MonoBehaviour {
       //两个物体能发生碰撞的条件是:两个都带有collider且其中一个是刚体。
        // Use this for initialization
        void Start () {
        
        }
        
        // Update is called once per frame
        void Update () {
        
        }
    /////////////////触发器////////////////////
        //刚进入触发范围的时候
        void OnTriggerEnter(Collider other)
        {
            print("进入触发范围");
        }
    
        //持续待在触发范围内
        void OnTriggerStay(Collider other)
        {
            print("持续触发");
        }
    
        void OnTriggerExit(Collider other)
        {
            print("离开触发范围");
        }
    //////////////////碰撞相关的三个函数////////////////////
        //发生碰撞的两个物体必须有相对运动
        //碰撞开始时调用一次,“与地面碰撞也会触发”
        void OnCollisionEnter(Collision other)
        {
            print("碰撞开始");
        }
        //有接触,且有相对移动
        void OnCollisionStay(Collision other)
        {
            print(other.gameObject.name);
            if(string.Equals("Cube2", other.gameObject.name))
            {
                print("与cube2发生了碰撞");
            }
            print("碰撞中");
        }
        //碰撞结束
        void OnCollisionExit(Collision other)
        {
            print("碰撞结束");
        }
        ///////////////////////////////////////////
    }
  • 相关阅读:
    centos 研究
    python学习6 web开发
    python学习5 常用三方模块
    python学习4 常用内置模块
    python学习 3笔记
    SQLite
    mysql
    python学习 2数学公式
    python学习 1基础
    shell example02
  • 原文地址:https://www.cnblogs.com/wrbxdj/p/5683223.html
Copyright © 2011-2022 走看看