这是我第一次使用Unity,而我却无法使拾取物品中的粒子脱落。编码在C#中。长话短说,粒子系统需要在玩家与拾取物品碰撞时开始工作。我经常运行项目或代码它不起作用我做错了什么?
using UnityEngine;
using System.Collections;
public class Particles : MonoBehaviour
{
public ParticleSystem part;
public ParticleCollisionEvent[] collisionEvents;
void Start()
{
part = GetComponent<ParticleSystem>();
collisionEvents = new ParticleCollisionEvent[16];
}
void OnParticleCollision(Particles other)
{
int safeLength = part.GetSafeCollisionEventSize();
if (collisionEvents.Length < safeLength)
collisionEvents = new ParticleCollisionEvent[safeLength];
int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents);
Rigidbody rb = other.GetComponent<Rigidbody>();
int i = 0;
while (i < numCollisionEvents)
{
if (rb)
{
Vector3 pos = collisionEvents[i].intersection;
Vector3 force = collisionEvents[i].velocity * 10;
rb.AddForce(force);
}
i++;
}
}