- Home /
shooting script wont work
this is my script that should make my weapon fire but in the console bar at the bottom an error comes up saying unexpected token: }. im hopeless with scripting so could someone please write me another one or correct me?
heres my script.
var projectile : Rigidbody; var speed = 20; function Update() } if( Input.GetButtonDown( "Fire1" ) ) }
var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation ); instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) ); Physics.IgnoreCollision( instantiatedProjectile. collider, transform.root.collider ); {
Answer by oliver-jones · Dec 06, 2010 at 06:55 PM
It helps if you place the code in the 'code' format (the 101010 icon in the post) - it puts people off the post when its not in the correct format. Anywhoo, this should work:
var projectile : Rigidbody; var speed = 20;
function Update() { if( Input.GetButtonDown( "Fire1" ) ){
var instantiatedProjectile : Rigidbody = Instantiate( projectile, transform.position, transform.rotation );
instantiatedProjectile.velocity = transform.TransformDirection( Vector3( 0, 0, speed ) );
Physics.IgnoreCollision( instantiatedProjectile. collider, transform.root.collider ); } }
Answer by FLASHDENMARK · Dec 06, 2010 at 07:45 PM
Your code look right, but i noticed that your brackets are facing the wrong way like so:
function Update
{
//Type stuff here :) <--- that is how it should look.
}
function Update
}
//This is the wrong way. <--- your brackets are turning the wrong way. That seems to be the problem. :)
{
Hoped that helped :)
Answer by Wesley S · Dec 29, 2010 at 05:03 PM
tnx Oliver the script works fine except for 1 thing the bullets spawn, But they dont go on the right angle when you play en you see the guns (the P90s) shoot but the bullet gos left instead of going straight away. can you help me out tnx greats wesley
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How would you make your player freeze for a certain amount of time? 2 Answers
How to use option setting Vibrate and Mute 1 Answer
Loadlevel and buttons... 2 Answers
Helpppp - AnimationState.layer ?????? -1 Answers