- Home /
My gun won't fire. ( Javascript )
I built my own gun with blender. I've only been using Unity and Blender for a few days. I watched this video. http://www.youtube.com/watch?v=NPlRbxJtKxE and used a script from this guys comment GyratinVibratinD1LD01 month ago
Heres the script that works . var projectile : Rigidbody; var speed = 10;
function Update () { if (Input.GetButtonUp ("Fire1")) { clone = Instantiate(projectile, transform.position, transform.rotation); clone.velocity = transform.TransformDirection(Vector3 (0, 0, speed));
Destroy (clone.gameObject, 5);
}}
I dragged a sphere into rigidbody for the spawn, which is placed at the muzzle of my gun. The sphere has a physics property of rigidbody. Here's my script.
var projectile : Rigidbody ; var speed = 10;
function update () {
if(Input.GetButtonUp ("Fire1")) { clone = Instantiate(projectile, transform.position, transform.rotation); clone.velocity = transform.TransformDirection(Vector3 (0, 0, speed));
Destroy (clone.gameObject, .25);
}}
If you could format your code correctly then it will be easier for me and others to help ^^
How do I format the code? I clicked the little box with the binary 101010 that says code sample. It gave me a box and I copied and pasted it. I have seen other forum posts with code how it looks in the script editor thing. I don't know how to do it that way.
Just select the code, and then press 101010 button. You'd need to do some indenting by yourself though.
Answer by ArkaneX · Jan 16, 2014 at 04:50 PM
Function names are case sensitive. Change update to Update.