MonoBehaviour.OnParticleCollision 当碰撞粒子

function OnParticleCollision (other : GameObject) : void

Description描述

OnParticleCollision is called when a particle hits a collider.

当粒子碰到collider时被调用。

This can be used to apply damage to a game object when hit by particles. This message is sent to all scripts attached to theWorldParticleCollider and to the Collider that was hit. The message is only sent if you enable sendCollisionMessage in the inspector of theWorldParticleCollider.

这个可以用于游戏对象被粒子击中时应用伤害到它上面。这个消息被发送到所有附加到theWorldParticleCollider 的脚本上和被击中的碰撞体上。这个消息只有当你在theWorldParticleCollider 检视面板中启用了sendCollisionMessage 才会被发送。

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void OnParticleCollision(GameObject other) {
		Rigidbody body = other.rigidbody;
		if (typeof(body)) {
			Vector3 direction = other.transform.position - transform.position;
			direction = direction.normalized;
			body.AddForce(direction * 5);
		}
	}
}

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

OnParticleCollision 可以被用作协同程序,在函数中调用yield语句。

最后修改:2011年1月2日 Sunday 16:26

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。