Unity入门操作

xiaoxiao2021-02-28  23

Collider——很简单,就是碰撞盒,有碰撞盒才有碰撞,所有碰撞的参与者都必须要有至少一个碰撞盒才行 碰撞器长用的有盒子,球形,胶囊,圆柱(等同胶囊)。 Trigger——这也是一个描述,同时是Collider的一个属性。被标记为Trigger的碰撞盒基本不再具备物理特性(如果绑有刚体的话,且使用重力,受重力下落)。 Trigger就是说如果执行下面的语句, void OnTriggerEnter(感应器(不会影响来感受的对向的物理量))(Collider other) {

if (other.transform.name == "other") { Debug.Log("****"); Destroy(other.gameObject, 0); } }

void OnCollisionEnter(碰撞器)(Collision col) {

if (col.transform.name == "other") { Debug.Log("123"); Destroy(col.gameObject, 0); } }

using UnityEngine; using System.Collections;

public class RigidBodyDemo : MonoBehaviour {

// Use this for initialization void Start () { //Rigidbody m_rigidbody = gameObject.GetComponent<Rigidbody>(); //m_rigidbody.mass = 2; //m_rigidbody.useGravity = false; } // Update is called once per frame void Update () { } //发生碰撞的条件: //主动方必须有Rigidbody 发生碰撞的两个游戏对象必须有Collider 被动方对于RigidBody可又不可无 //参数是表示被动方 void OnCollisionEnter(Collision col) { Debug.Log("开始碰撞" + col.collider.gameObject.name); } void OnCollisionStay(Collision col) { Debug.Log("持续碰撞中" + col.collider.gameObject.name); } void OnCollisionExit(Collision col) { Debug.Log("碰撞结束" + col.collider.gameObject.name); } //发生触发的条件: //发生碰撞的物体两者其中之一有Rigidbody即可 发生碰撞的两个游戏对象必须有Collider 其中一方勾选IsTrigger即可 //参数是表示被动方 void OnTriggerEnter(Collider other) { Debug.Log("触发器开始出发:" + other.gameObject.name); GameObject.Destroy(gameObject); Destroy(other.gameObject); } void OnTriggerStay(Collider other) { Debug.Log("触发器检测中:" + other.gameObject.name); } void OnTriggerExit(Collider other) { Debug.Log("触发器结束:" + other.gameObject.name); }

}

转载请注明原文地址: https://www.6miu.com/read-799991.html

最新回复(0)