Help, I need to make a particle emitter emit at MouseClick. I have gotten everything ready except the actual thing. I need to make the ellipsoid particle emitter emit, I really need some help. I have a main gameobject called gunprototype, and another object in it called maingun. The maingun object has the models etc. I have created a gameobject in the main 'gunprototype' object called Gun, and in Gun there is a ellipsoid particle emitter and the script. the problem is, it is giving me code errors like "cannot convert from UnityEngine.GameObject to UnityEngine.ParticleEmitter".
I tagged the emitter with the tag "Seagull".
function Update ()
{
var goEmitter : GameObject;
var emitter : GameObject;
goEmitter = GameObject.FindGameObjectsWithTag("Seagull");
if (Input.GetMouseButtonDown (0))
{
BroadcastMessage("Firing!");
goEmitter.Emitter.emit = true;
}
The error is because you're declaring 'emitter' as a GameObject, and then referring to it as a particleEmitter. I've updated your script and it should work (assuming that the gun is the only object with the "Seagull" tag (be aware that you can create your own tags too).
A few notes:
Put your 'Find' function in Awake() or Start() so it's only looked up once, and then cached.
FindGameObjectsWithTag returns an array of GameObjects, and you were only accessing the first.
You don't need Emitter. "particleEmitter" refers to the particleEmitter component on the gameObject.
Do you need to BroadcastMessage("Firing!") ? This attempts to call Firing!() on all GameObjects...
Hope this helps.
function Awake()
{
var goEmitter : GameObject = GameObject.FindWithTag("Seagull");
}
function Update ()
{
if (Input.GetMouseButtonDown (0))
{
BroadcastMessage("Firing!");
goEmitter.particleEmitter.emit = true;
}
}