Ok i have set bullets to be spawned on left mouse buton but what happens is bullets are firing without any left mouse press. infact millions of bullets are firing.
I am not using the Character Controller script as i can’t get it to work with rigidbody for my thrust.
var thrust = 0.1;
var bulletPrefab:Transform;
var bulletspeed = 1000;
function FixedUpdate () {
rigidbody.AddForce(transform.forward * thrust);
if (Input.GetKey ("up")) {
rigidbody.AddForce(Vector3.up);
Debug.Log("up arrow key is pressed");
}
if (Input.GetKey ("down")) {
rigidbody.AddForce(Vector3.down);
Debug.Log("down arrow key is pressed");
}
if (Input.GetKey ("left")) {
rigidbody.AddForce(Vector3.left);
Debug.Log("left arrow key is pressed");
}
if (Input.GetKey ("right")) {
rigidbody.AddForce(Vector3.right);
Debug.Log("right arrow key is held pressed");
}
//Check to see if LEFT MOUSE button is pressed then fire
if(Input.GetMouseButtonDown(0).ToString())
{
var bullet = Instantiate(bulletPrefab, GameObject.Find("spawnPoint").transform.position,Quaternion.identity);
bullet.rigidbody.AddForce(transform.forward * bulletspeed);
}
}
P.S.
Can you remove the Box Collider if you have added rigidbody…?