- Home /
I am making android fps and my raycast shooting button don't work. What I should do?
I have android fps touch control and it works great. But fps shooter needs gun also. So I made I script for touchscreen raycast shooting. It shoots, but bad thing is everytime when I touch screen it shoots (example when I look around or move or just touch some random point on screen). And the button what I made for raycast shooting don't do anything, so when I press the button nothing happens. Yellow button is the raycast shooting button, red is sight for raycast shooting and fps moving and looking around are in right and left corners on photo. So can you awesome people help me? :)
HERE IS MY CODE:
var fireButton : GUITexture;
var Effect : Transform;
var TheDammage = 100;
var sound : AudioClip;
function Update(){
for (var evt : Touch in Input.touches) {
var HitTest1 = fireButton.HitTest(evt.position);
if (evt.phase == TouchPhase.Began) {
if(HitTest1){
audio.PlayOneShot(sound);
audio.Play();
}
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*0.5, Screen.height*0.5, 0));
if (Physics.Raycast (ray, hit, 100))
{
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
}
}
Answer by robertbu · Jan 15, 2014 at 04:53 PM
You are almost there. Your Raycast() code needs to be inside your if(HitTest1) condition. Your indentation here is a bit messed up, but if you move the '}' bracket on line 18 down to line 29, your code should work.
Sorry I am not good at coding.., could you copy and write fixed code in here? Because I dont understand all what you say (I'm not good at english). And say to your people that you have done amazing work and you have good customerservice!