- Home /
Help with gun scripting!?
I started using Unity from yesterday and I have tried to script a gun to fire through java script and the bullets fire out sideways!? any help
Heres the Script
var BulletPrefab:Transform; var force : float = 6000;
function Update() { if(Input.GetButtonDown("Fire1")) { var bullet = Instantiate(BulletPrefab,
GameObject.Find("spawnPoint").transform.position,
GameObject.Find("Gun").transform.rotation);
bullet.rigidbody.AddForce(transform.forward * force);
} }
Answer by Loius · Jun 29, 2012 at 02:43 PM
The rotation you're passing in there is wrong.
You're calling GameObject.Find, which returns the first object of all your objects that is named 'whatever'. And it's very slow.
You want to cache gameObject.Find (note the lowercase G) as local variables for performance reasons.
Either your gun's forward isn't forward or you're Finding the wrong object.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
I Need Help Whit Gun! 2 Answers
Bullet still goes sideways... 1 Answer
Bullet Hole not inline with sight?(Center of Screen) 1 Answer
having trouble with ammo reload script. destorys extra ammo 1 Answer