- Home /
FPS Switching Weapons on iPhone
Hi, I created a FPS game using the Unity FPS tutorial http://unity3d.com/support/resources/tutorials/fpstutorial.html
The game has a machine gun and rocket launcher attached to the FPS controller. The game was built in a Mobile unity file "FirstPersonTilt.unity" then transfered to an iPod Touch.
On the computer, pressing 2 turns on rocket launcher, pressing 1 switches back to machine gun.
How do I switch weapons on the iPod touch. Is there a code to switch weapons touching the iPod screen?
Any help is apprecated. Thank you
Answer by samm565_ · Jul 11, 2011 at 09:27 AM
I am doing the same thing you are. I figured it out though. Use this instead of the PlayerWeapons.js script. It creates a button that toggle's the weapons. I had some problems with my secondary weapon equipping first but i think i didn't follow the tutorial correctly, actually i didn't really follow the tutorial at all. So you may have to change 1 or 2 little things in it. But this should atleast get you started.
private var RifleEquip = true;
function Start () {
SelectWeapon(1);
}
function OnGUI() {
if (GUI.RepeatButton (Rect (85,Screen.height - 80,75,75), "Shoot")) {
BroadcastMessage("Fire");
}
if (RifleEquip==true) {
if (GUI.Button (Rect (Screen.width - 210,5,50,75), " ")) {
SelectWeapon(1);
RifleEquip = false;
}
}
if (RifleEquip==false) {
if (GUI.Button (Rect (Screen.width - 210,5,50,75), " ")) {
SelectWeapon(0);
RifleEquip = true;
}
}
}
function SelectWeapon (index : int) {
for (var i=0;i<transform.childCount;i++) {
if (i == index)
transform.GetChild(i).gameObject.SetActiveRecursively(true);
else
transform.GetChild(i).gameObject.SetActiveRecursively(false);
}
}
Your answer
Follow this Question
Related Questions
Weapon Switch Animations 1 Answer
Making An Automatic Weapon from FPS Tutorial 0 Answers
Basic First Person Shooter Weapon Setup!?!?! 1 Answer
FPS recoil, lerp fighting 0 Answers