- Home /
Problem with shooting script
okay, so i've created a script that has no errors in it. But the problem is that it does NOT do what i want it to do! I want it to shoot out a bullet( in this case a cube) out of the gun. but noting happens when i press left click.
var BulletPrefab:Transform;
var force : float = 2000;
function Update ()
{if(Input.GetMouseButtonDown(0))
{var bullet = Instantiate(BulletPrefab,
GameObject.Find("spawnPoint").transform.position,
GameObject.Find("AK-47M").transform.rotation);
bullet.rigidbody.AddForce(bullet.transform.forward * force);
}
}
as i said, there are no errors which makes it unable to copy and use. it just doesn't do what i want it to do.
Answer by robertbu · Feb 13, 2013 at 01:30 AM
Your script works fine for me. Make sure you are not receiving any error messages in the Console window. Look in the hierarchy after each press of the mouse button. Is there a new bullet listed? If the bullet is listed, select it to see it position and rotation. Are the game object associated with "spawnPoint" and "AK-47M" creating something that is visible to the camera?
Answer by AMU4u · Mar 21, 2015 at 06:49 PM
Change if(Input.GetMouseButtonDown(0))
to if(Input.GetMouseButtonDown("Fire1"))
I've never seen numbers used unless like the numerical values. The script works for me.