I am trying to move AND shoot (one bullet at a time) but what ends up happening is that I do either or, not both.
using UnityEngine;
using System.Collections;
public class shootingscript : MonoBehaviour
{
public GUITexture guiShoot;
public GUITexture guiLeft;
public GUITexture guiRight;
bool buttonShoot = false;
bool buttonLeft = false;
bool buttonRight = false;
void ReadButtons ()
{
if (Input.touchCount > 0)
{
// Get the touch info
Touch t = Input.GetTouch(0);
// Did the touch action just begin?
if (t.phase == TouchPhase.Began) {
if(guiShoot.HitTest (t.position))
Button ();
if (guiLeft.HitTest (t.position))
buttonLeft = true;
if (guiRight.HitTest (t.position))
buttonRight = true;
}
// Did the touch end?
if (t.phase == TouchPhase.Ended) {
buttonLeft = false;
buttonRight = false;
buttonShoot = false;
}
}
}
void Update()
{
ReadButtons ();
if (buttonRight){
transform.Translate(Vector2.right * 4f *Time.deltaTime);
transform.eulerAngles = new Vector2(0, 0);
}
if (buttonLeft){
transform.Translate(Vector2.right * 4f * Time.deltaTime);
transform.eulerAngles = new Vector2(0, 180);
}
}
void Button ()
{
WeaponScript weapon = GetComponent<WeaponScript>();
if (weapon != null)
{
weapon.Attack(false);
}
}
}