- Home /
Is there any way to empty the touch array.
hey, I'm creating a shooting game for mobile platform but i'm facing problem in touch.It is a shooting game so player have to press the button continuously,but after some time bullet creation is stop and if i leave the control for 1-2sec it start instantiate again.I'm using GUITexture for touch response. here is the code:-
`if (Input.touchCount > 0) {
for (int i = 0; i < Input.touchCount; i++)
{
Touch touch = Input.GetTouch(i);
if (touch.phase == TouchPhase.Began)
{
if(this.mJumpGUI.guiTexture.HitTest(touch.position)){
this.isclicked = true;
}
if (this.mFireGUI.guiTexture.HitTest(touch.position)){
this.isPressed = true;
this.isFired = false;
}
}
}
}
//bullet code
if (this.isPressed)
{
this.myAnimation.SetAnimation(2);
if (this.myAnimation.GetCurrentFrame() == 2)
{
if (!this.isFired)
{
this.CreateBullet(States.globalPSet._multibullet);
this.isFired = true;
this.mBulletFireTimer = (float)0;
}
}
else
{
this.isFired = false;
}
}
//bullet funtion
public void CreateBullet(bool single)
{
this.PlaySound();
checked
{
if (!single)
{
GameObject gameObject = (GameObject)Instantiate(this.mBulletprefab, new Vector3(this.transform.position.x, unchecked(this.transform.position.y + 0.5f), this.transform.position.z), Quaternion.identity);
gameObject.rigidbody.AddForce(Vector3.up * this.mBulletSpeed, ForceMode.VelocityChange);
PlayerControl.mBulletList.Add(gameObject);
}
else
{
this.CreateMultiBullet();
}
}
}
this function is inside the update(), player have to press the button each time to create a bullet.
it is a mul$$anonymous$$ch game so i have to check every touch.user can access both control at same time.
can you post the part of the script that creates the bullets?
Haven't worked with Input.GetTouch yet, so I'm not sure whats wrong.
Try some debugging.
Debug the amount of bullets you are creating (see if it always stops at the same amount).
Debug the Input.GetTouch (see if it doesn't behave as expected).
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to get position of touch on touch screen 1 Answer