I am trying to make my guns fire bullets you know like guns do XD but the script that I am using dosnt work and I was wondering if anyone could help me fix it. I am using the newest version of Unity. code I have now:
var projectile : Rigidbody;
var initialSpeed = 20.0;
function Fire () {
var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation);
instantiatedProjectile.velocity = transform.TransformDirection(Vector3 (0, 0, initialSpeed));
Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider);
}
function Update ()
{
if (Input.GetButtonDown("Fire1")) {
Fire();
}
}
can someone please help solve this problem soon thank you for you help.
What is it that doesn't work? Could you please provide more information?
– Statementjust checking, have actually specified the rigidbody that you are instantiating in the inspector
– ScribeShouldn't you be firing the Transform that contains the rigidbody? I'd guess that you might be firing it (do you see a new GameObject pop up?) but it has no mesh, so you don't see anything.
– Owen-ReynoldsThe Bullet fires only one way if i turn left it fires right if I turn back it fires straight
– anon34150999