Instantiating a Prefab based on Input(Javascript)

Hi I am making a 2d side scroller where my ship has 3 forms. The forms are changed using Input.GetKeyDown. When my player’s ship enters for instance Fire form, I would like a Particle System to envelop the players ship with a red colored aura. My problem is since I have 3 elemental auras and one ultimate aura I need to be able to tell Unity which Aura Prefab to attach to the player at the moment of input. Also how do you “stick” it to the ship so after it has changed forms the aura stays around the ship while its moving, instead of just staying at the point where it was “called”

Alot of this script isnt finished so some of the statements dont do anything yet. Thanks for the help.

var playerSpeed : int;
var playerLives : int;
var playerHealth : int;
var playerAura : Transform;

static var isEarthForm : boolean = false;
static var isFireForm : boolean = false;
static var isWaterForm : boolean = false;
static var isUltimateForm : boolean = false;


static var playerFormPoints : int;
static var playerScore : int;
static var bulletPower : int = 1;


var bullet : Rigidbody;
var explosion : Transform;



function Update () {
	//how much to move the player
	amtToMoveX = (playerSpeed * Input.GetAxis("Horizontal")) * Time.deltaTime;
	amtToMoveY = (playerSpeed * Input.GetAxis("Vertical")) * Time.deltaTime;

	//translate player
	transform.Translate(Vector3.right * amtToMoveX);
	transform.Translate(Vector3.up * amtToMoveY);


	//looks to see if left mouse button is prssed, if it is, fires a bullet
	if(Input.GetKeyDown("mouse 0")){
		var tempBullet : Rigidbody;

		tempBullet = Instantiate(bullet, transform.position, transform.rotation);
	}

	//activates Ultimate Form
	if(Input.GetKeyDown("q" || "v")){
		if(playerFormPoints > 2){
		
			isUltimateForm = true;
			bulletPower = 3;
			print("Ultimate Form Achieved");
		}
	}

	//activates Fire Form
	if(Input.GetKeyDown("f" || "c")){
		isFireForm = true;
		print("Fire Form Achieved");
	}

	//activates Water Form
	if(Input.GetKeyDown("r" || "x")){
		isWaterForm = true;
		print("Water Form Achieved");
	}

	//activates Earth Form
	if(Input.GetKeyDown("e" || "z")){
		isEarthForm = true;
		print("Earth Form Achieved");
	}

}//end update

function OnGUI(){
	GUI.Label(Rect(10,10,200,50), "Score: " + playerScore);
	
	GUI.Label(Rect(10,30,200,50), "Lives: " + playerLives);
	
	GUI.Label(Rect(10,50,200,50), "Health: " + playerHealth);
	
	GUI.Label(Rect(10,70,200,50), "Perfect Form: " + playerFormPoints);
}

function OnTriggerEnter(otherObject : Collider){
	if(otherObject.gameObject.tag == "enemy" || otherObject.gameObject.tag == "enemyBullet"){
		playerHealth--;

		//respawns enemy
		otherObject.gameObject.transform.position.x = 30;
		otherObject.gameObject.transform.position.y = Random.Range(-13,11);
	
	
		var tempExplosion : Transform;
		
		tempExplosion = Instantiate(explosion, transform.position, transform.rotation);
	}

}

As it is sometimes usefull to instantiate a prefab on input ( => Instantiate(prefab, pos, Quaternion.identity).transform.parent = transform.parent), this isn’t the case here.

You should have all the particle systems you need as children of your ship. If it’s Shuriken, make sure they don’t pley on awake, if it’s legacy they must have emit disabled. Then Play / Emit the one you need when you need it.

About sticking part, try changing the space of the particle system.

Thanks for your input guys, I understand the concept your trying to convey I just don’t really understand how to execute it properly. I made the changes to my code suggested, I parent’ed my player’s ship to the auras, turned the aura’s emit off, and cleaned up the boolean code like suggested but I’m getting an error saying

“MissingFieldException: Field ‘CompilerGenerated.playerScript_Update$callable1$93_36.particleEmitters’ not found.”

I know it’s a simple solution from here but I am only a month into learning Unity/Jscript coming from Java.

this playerScript is attached to my player game object, in the inspector I have added the auras into the element fields in the correct order.

Im thinking my problem is how I’m initializing the array. Also having trouble getting to the emit in each of the children and setting it to true.
I have attached the relevant code… thanks for your help.

var particleEmitters : ParticleEmitter[]; 

function Awake () {
	
	particleEmitters = gameObject.GetComponentsInChildren(ParticleEmitter) as ParticleEmitter[];
	
}

function Update () {
//looks to see if left mouse button is prssed, if it is, fires a bullet
	if(Input.GetMouseButtonDown(0)){
		var tempBullet : Rigidbody;

		tempBullet = Instantiate(bullet, transform.position, transform.rotation);
	}

	//activates Ultimate Form
	if(iKD("q") || iKD("v")){
		//checks to see if form is currently active, if it is it turns it off and reloads Update                      ////////////////ALL 4 FORMS STILL NEED TO SHUT OFF AURAS DEPENDING ON
		if(isUltimateForm == true){																					  ////////////////INPUT	WHEN A KEY FOR AURA IS PRESSED BUT ITS ALREADY ACTIVE
			isUltimateForm = false;	
			Update();
		}
		
		
		if(playerFormPoints > 2){
			gameObject.GetComponentInChildren.particleEmitters[3].emit = true;
			isUltimateForm = true;
			bulletPower = 3;
			print("Ultimate Form Achieved");
		}
		
		
	}

	//activates Fire Form
	if(iKD("f") || iKD("c")){
		//checks to see if form is currently active, if it is it turns it off and reloads Update
		if(isFireForm == true){
			isFireForm = false;	
			Update();
		}
		
		
		gameObject.GetComponentInChildren.particleEmitters[0].emit = true;
		isFireForm = true;
		print("Fire Form Achieved");
	}

	//activates Water Form
	if(iKD("r") || iKD("x")){
		//checks to see if form is currently active, if it is it turns it off and reloads Update
		if(isWaterForm == true){
			isWaterForm = false;	
			Update();
		}
		
		
		
		gameObject.GetComponentInChildren.particleEmitters[1].emit = true;
		isWaterForm = true;
		print("Water Form Achieved");
	}

	//activates Earth Form
	if(iKD("e") || iKD("z")){
		//checks to see if form is currently active, if it is it turns it off and reloads Update
		if(isEarthForm == true){
			isEarthForm = false;	
			Update();
		}
		
		
		gameObject.GetComponentInChildren.particleEmitters[2].emit = true;
		isEarthForm = true;
		print("Earth Form Achieved");
	}

}//end update