- Home /
error CS0246: The type or namespace name `ParticleCollisionEvent' could not be found. Are you missing a using directive or an assembly reference?
I am trying to write a script where if the player pressed down on the mouse, a Boolean called "Hover" would equal yes. If the player object was "hovering" while in collision with my particle system, the player would rise in the y axis. However I get a namespace error on ParticleCollsionEvent which is weird since I'm adapting code from the Unity documentation page: http://docs.unity3d.com/ScriptReference/MonoBehaviour.OnParticleCollision.html In addition, I'm also getting parsing and unexpected symbol errors which I'm not sure how to fix. Here is what I have so far:
using UnityEngine; using System.Collections;
public class HoverScript : MonoBehaviour {
public float Hoverforce;
public ParticleSystem part;
public ParticleCollisionEvent[] collisionEvents;
public bool Hover;
// Use this for initialization
void Start () {
part = GetComponent<ParticleSystem>();
collisionEvents = new ParticleCollisionEvent[16];
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown ("mouse0"))
Hover = true;
}
void OnParticleCollison (GameObject other) {
int safeLength = part.safeCollisionEventSize;
if (collisionEvents.Length < safeLength)
collisionEvents = new ParticleCollisionEvent[safeLength];
int numCollisionEvents = part.GetCollisionEvents(other, collisionEvents);
int i = 0;
while (i < numCollisionEvents && Hover = true) {
other.rigidbody.AddForce(Vector3.up * Hoverforce, ForceMode.Acceleration);
}
i++;
}
}
Any advice would be useful thanks!
Answer by PimajeXenja · Apr 23, 2015 at 04:13 AM
Figured it out! For anyone not using Unity 5, you have to change ParticleCollisionEvent[] to ParticleSystem.CollisionEvent[].
Answer by HarshadK · Apr 17, 2015 at 09:31 AM
When I tried your script I did not receive any such error as you stated. But there were unexpected symbol and parsing errors though.
In your while you should check for equality of Hover using '==' as below:
while (i < numCollisionEvents && Hover == true) {
Also I think your
i++;
should be inside your while loop and not outside.
Thank you Harshad$$anonymous$$! Adding the missing equal sign, and moving the i++ removed all of my errors except for the namespace error. Just to make sure I wasn't doing something wrong, I copied the whole C# particle collision script from the documentation into a new script file and I get the same error Would my Unity editor version have anything to do with it? I am using 4.6.4.
Answer by PimajeXenja · Apr 23, 2015 at 04:13 AM
Figured it out! For anyone not using Unity 5, you have to change ParticleCollisionEvent[] to ParticleSystem.CollisionEvent[].
Your answer
Follow this Question
Related Questions
How do I make instantiated particles inherit Transform movement from their parent object? 1 Answer
Particle Playback Error in 5.4 0 Answers
Emit particles by distance of parent 2 Answers
Shuriken particle System - change velocity by trigger 0 Answers
How to edit particle system size over lifetime curve with script? 0 Answers