Hello Unity3D.I have a question about spawning?How can i make it that whenever i use the functions GetKey Or GetButton i only spawn 1 and only 1 gameObject?For example whenever i use GetButton For my Player He spawn Over hundreds of the same gameObject.I dont want that.I want him to spawn 1 and only 1 of the same gameObject.If anyone knows how i can make it that my player spawn 1 gameObject by using GetButton or GetKey.Can you please tell me how?
Heres What i got So Far
#pragma strict
var ChargeButton : String = “Charge_P1”;
var ChargeEffect : GameObject;
var ChargeSpawn : Transform;
var numShots : float = 1;
private var anim: Animation;
function Awake() {
anim = GetComponent.<Animation>();
}
function Start() {
if (numShots / 1 * 1 == numShots) numShots++; // Need an odd number of shots
if (numShots < 1) numShots = 1; // At least 3 shots for a fan
}
function Update() {
for(var i = 1; i < numShots; i++)
if (Input.GetButton(ChargeButton)) {
anim.Play("Charge");
anim["Charge"].speed =.50;
Instantiate(ChargeEffect,ChargeSpawn.transform.position,ChargeSpawn.transform.rotation);
Debug.Log("User pressed C");
}
else{
if(Input.GetButtonUp(ChargeButton))
Destroy(ChargeEffect);
anim.Stop("Charge");
}
}