So the fix here is
1. Switch
anim = gameObject.GetComponent();
becomes
anim = Player.GetComponent();
2. The foreach loop goes into an if statement based on the number of touches as Dblfstr suggests and the code in the else if goes into and else after that, so:
void Update () // If the screen is touched
{
if ( Input.touchCount > 0 )
{
if (guiTexture.HitTest(touch.position)) // If the gui texture is touched then
{
foreach (Touch touch in Input.touches)
{
guiTexture.texture = button2; // The button changes to button2
Player.transform.Translate(Vector3.right * speed * Time.smoothDeltaTime); // Player slowly moves to the right
anim.SetBool ("run_right", true);
}
}
else // until the player stops touching the screen
{
guiTexture.texture = button1; // gui texture reverts back to the original
anim.SetBool ("run_right", false);
}
}
}
↧