- Home /
Hello I have a gun swich script that doesn't work can someone help me please?
Hi everyone,
I am making a FPS game but my Gun swich doesn't work can someone help me please?
Here's the script:
//change gun script
var First Weapon : Object; var secondary Weapon : Object;
function Update: (){ if(Input.GetKeyDown(1)){ (FirstWeapon)=true; (Secondary Weapon)=false; else if(Input.GetkeyDown(2)){ (FirstWeapon)=false; (Secondary Weapon)=true; }
if (Input.GetKeyDown(*2)){ Play.Animation : Secondary Weapon.once;
else
Play.Animation : First Weapon.once; }
}
Thank you if you can help me with it :)
Answer by hijinxbassist · May 25, 2012 at 01:48 AM
var firstWeapon : Transform;
var secondaryWeapon : Transform;
function Update()
{
if(Input.GetKeyDown("1"))
{
firstWeapon.renderer.enabled=true;
secondaryWeapon.renderer.enabled=false;
}
else if(Input.GetKeyDown("2"))
{
firstWeapon.renderer.enabled=false;
secondaryWeapon.renderer.enabled=true;
}
}
There were sooooo many errors on this script. Ive managed to fix all the errors. Im going with the assumption that both guns are where they need to be in front of the character and do not have colliders attached. I just turn off the individual renderers, this is not the "real" way to do this but is much closer to the expected result you want.
Lets talk some basics now..
Variables DO NOT have spaces "first weapon" is not proper, firstWeapon is.
There is no " : " after a function name. Update: () is bad, Update() is proper.
When using a function that uses a string overload use quotation marks"", not asterisks**
An Object cannot be set to True or False. Only a boolean can be True or False (such as an if statement, which returns a boolean / Either True or False)
That covers the majority of errors i see..my suggestion is to Read The Scripting Ref found http://unity3d.com/support/documentation/ScriptReference/>Here, and read up on proper javascript syntax. Hope this helps you with your coding
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Gun movement 1 Answer
Problem with my weapon change system 0 Answers
How can i have 3 weapon to switch between?? 1 Answer
Weapon switching 1 Answer