I, I’ve got some code that calls a routine to throw an object when the P key is pressed, it all works fine except every time I press the P key he throws the object + 1 more every time, I’m using (Input.GetKeyDown) can someone please point out the obvious that I’m missing please.
var ThrownObject : Transform; // Set var for a object to throw
var Explosion : Transform; // Set var for the exposion to use
function Chuk()
{
animation[“Throw”].layer = 1;
animation.CrossFade(“Throw”,0.2);
animation[“Throw”].blendMode = AnimationBlendMode.Additive; // set the blend mode to Additive so it will blend
// into whatever animation is playing when it’s called
function throwObject()
{
// Add a var ThrownObject : Transform; at top of script then drag the object you want
// to throw into it in the inspector window
var bullit = Instantiate(ThrownObject, GameObject.Find(“throwSpawnPoint”).transform.position, Quaternion.identity);
bullit.rigidbody.AddForce(transform.forward * 2000);
var bang = Instantiate(Explosion, GameObject.Find(“throwSpawnPoint”).transform.position, Quaternion.identity);
}
I’ve cleaned the scrip up and added the ThrowObject.js to my model, but every time it’s called it adds 1, so it first throws 1 fireball then 2 then 3, and on and on until I reset the game, below are the 2 scrips, any help please?
function Chuk()
{
// Create and set up the AnimationEvent
var throwObjectEvent = new AnimationEvent();
throwObjectEvent.functionName = “throwObject”;
throwObjectEvent.time = 0.5;
animation[“Throw”].layer = 1; // Place the Throw animation on a higher level
animation[“Throw”].clip.AddEvent(throwObjectEvent); // Add the event to an AnimationClip
animation[“Throw”].blendMode = AnimationBlendMode.Additive; // set the blend mode to Additive so it will blend
// into whatever animation is playing when it’s called
animation.CrossFade(“Throw”,0.2); // Play the animation
}
The first script then calls this one that keeps repeating …
var ThrownObject : Transform; // Set var for a object to throw
var Explosion : Transform; // Set var for the exposion to use
function throwObject()
{
var bullit = Instantiate(ThrownObject, GameObject.Find(“throwSpawnPoint”).transform.position, transform.rotation);
bullit.rigidbody.AddForce(transform.forward * 2000);
Instantiate(Explosion, GameObject.Find(“throwSpawnPoint”).transform.position, transform.rotation);
}