- Home /
selecting multable weapons
I have a 5 or 6 weapons that the player can use. each is assigned to a different button but i would like to be able to select a weapon with only only a single button or two buttons for cycling through from weapon one to weapon six etc.
Answer by Atnas1010 · Nov 03, 2010 at 11:53 PM
Something like this?
var currentWeapon : int = 0;
function Update () { if (Input.GetKeyDown(KeyCode.LeftArrow)) currentWeapon--; if (Input.GetKeyDown(KeyCode.RightArrow)) currentWeapon++; if (currentWeapon<0) currentWeapon = 5; else if (currentWeapon>5) currentWeapon = 0; }
wow thanks so much this is perfect. im new to scrpting could not figure this out
I am trying to use this on Android but can;t make it work. Here's my code:
var currentWeapon : int = 0;
var FireButtonStyle : GUIStyle;
var NextWeaponStyle : GUIStyle;
var PreviousWeaponStyle: GUIStyle;
function OnGUI (){
if (GUI.Button (Rect (730, 10, 60, 60), "", NextWeaponStyle))
currentWeapon--;
if (GUI.Button (Rect (730, 75, 60, 60), "", PreviousWeaponStyle))
currentWeapon++;
if (currentWeapon<0)
currentWeapon = 5;
else if (currentWeapon>5)
currentWeapon = 0;
if (GUI.RepeatButton (Rect (577, 383,66,88), "", FireButtonStyle))
Broadcast$$anonymous$$essage("Fire");
}
Any ideas? Thanks!
Your answer
Follow this Question
Related Questions
Weapons Cool Down 1 Answer
how to make something shoot the angle i am facing 2 Answers
Managing different weapons in scripting. 4 Answers
2.5D Melee 0 Answers
Weapon Pickup and Drop 0 Answers