Problem is not reproducible or outdated
Move Player (y-Axis) on click button does not work
ButtonMovement SCRIPT:
using UnityEngine; using System.Collections;
public class ButtonMovement : TouchManager { public bool moveRight = false; public float moveSpeed = 5.0f; public GameObject player = null;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
TouchInput();
}
void OnFirstTouch()
{
if (moveRight)
{
player.transform.Translate (Vector2.right * moveSpeed * Time.deltaTime);
}
else if (!moveRight)
{
player.transform.Translate (-Vector2.right * moveSpeed * Time.deltaTime);
}
}
void OnSecondTouch()
{
if (moveRight)
{
player.transform.Translate(Vector2.right * moveSpeed * Time.deltaTime);
}
else if (!moveRight)
{
player.transform.Translate(-Vector2.right * moveSpeed * Time.deltaTime);
}
}
}
TouchManager SCRIPT:
using UnityEngine; using System.Collections;
public class TouchManager : MonoBehaviour { public static bool guiTouch = false;
public void TouchInput ()
{
//GUI TEXTURES ONLY
if(GetComponent<GUITexture>() != null)
{
if (GetComponent<GUITexture>().HitTest(Input.GetTouch(0).position))//0=first touch
{
guiTouch = true;
switch (Input.GetTouch(0).phase)
{
case TouchPhase.Began:
SendMessage("OnFirstTouchBegan");
SendMessage("OnFirstTouch");
break;
case TouchPhase.Moved:
SendMessage("OnFirstTouchMoved");
SendMessage("OnFirstTouch");
break;
case TouchPhase.Stationary:
SendMessage("OnFirstTouchStationary");
SendMessage("OnFirstTouch");
break;
case TouchPhase.Ended:
SendMessage("OnFirstTouchEnded");
SendMessage("OnFirstTouch");
guiTouch = false;
break;
}
}
if (GetComponent<GUITexture>().HitTest(Input.GetTouch(1).position))//1=second touch
{
guiTouch = true;
switch (Input.GetTouch(1).phase)
{
case TouchPhase.Began:
SendMessage("OnSecondTouchBegan");
SendMessage("OnSecondTouch");
break;
case TouchPhase.Moved:
SendMessage("OnSecondTouchMoved");
SendMessage("OnSecondTouch");
break;
case TouchPhase.Stationary:
SendMessage("OnSecondTouchStationary");
SendMessage("OnSecondTouch");
break;
case TouchPhase.Ended:
SendMessage("OnSecondTouchEnded");
SendMessage("OnSecondTouch");
guiTouch = false;
break;
}
}
}
}
}
I have a 2d rigidbody Player which is falling on the ground. Both got box collider 2d. I add ButtonMovement to button left and button right and checked the move right [x] on button right. I added my Player to both scripts in my Buttons.
By pressing those Buttons, nothing happens. Any help? Its an Android app!
Follow this Question
Related Questions
Mobile Left and right move input for the player in 2D (Top Down) 0 Answers
[Help] Player stops moving when hitting wall diagonally 0 Answers
Hit a wall in my RTS movement controller. Issues with MoveToward and Coroutine logic. 0 Answers
Navmesh based player movement 1 Answer
Move an sphere when button clicked 0 Answers