- Home /
A script stopped working!
I modified the PlayerWeapons script from FPS tutorial to pick up GUI Texture taps. This script worked perfectly fine, even after modification, and just stopped working:
var fireButton : GUITexture;
function Start () {
SelectWeapon(0);
}
function Update(){
for (var evt : Touch in Input.touches) {
var HitTest1 = fireButton.HitTest(evt.position);
if (evt.phase == TouchPhase.Began) {
if(HitTest1){
//do something when button is hit
BroadcastMessage("Fire");
Debug.Log("Shooting");
}
}
}
}
function SelectWeapon (index : int) {
for (var i=0;i<transform.childCount;i++) {
// Activate the selected weapon
if (i == index)
transform.GetChild(i).gameObject.SetActiveRecursively(true);
// Deactivate all other weapons
else
transform.GetChild(i).gameObject.SetActiveRecursively(false);
}
}
Answer by Bunny83 · Feb 03, 2012 at 12:20 PM
Ok, maybe you should check your "something" a bit closer. This script have to be attached to a Gameobject that has the different weapons as child objects.
Your weapons need another script that react to the "Fire" message.
There's not much more to say about that. We don't see your project, we don't see your other script nor your hierarchy setup.
edit
Btw. "Touch" only works on mobile devices, just in case...
That didn't work. But it's okay, cause I found another way! ;)
Your answer
Follow this Question
Related Questions
(Game.Name) unfortunately stopped working after going to another app 1 Answer
Unity editor stopped working while importing package and open project 0 Answers
App has stopped working in Unity 2018.2.4 0 Answers
How to Stop Transform.Position in X-axis = 0 ? 1 Answer
Crash At The Start Of The Game 1 Answer