首页 > 其他 > 详细

Unitty 3D 贪吃蛇 今日小记 -- 碰撞

时间:2017-06-17 22:13:49      阅读:346      评论:0      收藏:0      [点我收藏+]

当蛇头碰撞到蛋的时候  应该让蛋消失并且重新创建蛋。

void OnTriggerEnter    可以使用这个方法 下面附有这个方法的介绍

其次需要对挂载在之上的Object  check IsTrigger 属性。

如果是 Prefab 预设体   需要在预设体处 进行Apply 操作。

 

MonoBehaviour.OnTriggerEnter(Collider)

 
 

Parameters

other The other Collider involved in this collision.

Description

OnTriggerEnter is called when the Collider other enters the trigger.

This message is sent to the trigger collider and the rigidbody (or the collider if there is no rigidbody) that touches the trigger. Notes: Trigger events are only sent if one of the colliders also has a rigidbody attached. Trigger events will be sent to disabled MonoBehaviours, to allow enabling Behaviours in response to collisions. (碰撞的两个物体必须要有一个具有刚体属性)

// Destroy everything that enters the trigger

function OnTriggerEnter (other : Collider) { Destroy(other.gameObject); }
using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { void OnTriggerEnter(Collider other) { Destroy(other.gameObject); } }

OnTriggerEnter can be a co-routine, simply use the yield statement in the function.

Unitty 3D 贪吃蛇 今日小记 -- 碰撞

原文:http://www.cnblogs.com/mythdoraemon/p/7041358.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!