Question by
SandipSarna · Aug 10, 2017 at 07:34 PM ·
scripting problemunityeditor
attachedRigidbody issue .
Hi, I am getting error with this script. Can any one go through it and correct it? It is associated to attachedRigidbody nad MonoBehaviour i think.
Thanks
using System;
using UnityEngine;
namespace UnityStandardAssets.Effects
{
public class WaterHoseParticles : MonoBehaviour
{
public static float lastSoundTime;
public float force = 1;
private ParticleCollisionEvent[] m_CollisionEvents = new ParticleCollisionEvent[16];
private ParticleSystem m_ParticleSystem;
private void Start()
{
m_ParticleSystem = GetComponent<ParticleSystem>();
}
private void OnParticleCollision(GameObject other)
{
int safeLength = m_ParticleSystem.GetSafeCollisionEventSize();
if (m_CollisionEvents.Length < safeLength)
{
m_CollisionEvents = new ParticleCollisionEvent[safeLength];
}
int numCollisionEvents = m_ParticleSystem.GetCollisionEvents(other, m_CollisionEvents);
int i = 0;
while (i < numCollisionEvents)
{
if (Time.time > lastSoundTime + 0.2f)
{
lastSoundTime = Time.time;
}
var col = m_CollisionEvents[i].colliderComponent;
if (other.GetComponent<Rigidbody> != null)
{
Vector3 vel = m_CollisionEvents[i].velocity;
other.GetComponent<Rigidbody>.AddForce(vel*force, ForceMode.Impulse);
}
other.BroadcastMessage("Extinguish", SendMessageOptions.DontRequireReceiver);
i++;
}
}
}
}
Comment