Question by
CobOfTheCorn · Apr 30, 2018 at 11:21 PM ·
iosmobiletouch controlstutorials
How to change movement script to iOS touch controls.
I am new to mobile and I was wondering if there was a simple way to change my controls from keyboard to iOS touch. I only need left and right controls and would appreciate any information or even a link to a good tutorial on iOS scripting.
public class Guy : MonoBehaviour
{
private bool isDead = false;
private Animator anim;
void Start ()
{
anim = GetComponent<Animator>();
}
void Update()
{
Movement();
}
void Movement()
{
if (isDead == false)
{
if (Input.GetKey(KeyCode.D))
{
transform.Translate(Vector2.right * 4f * Time.deltaTime);
transform.eulerAngles = new Vector2(0, 0);
}
if (Input.GetKey(KeyCode.A))
{
transform.Translate(Vector2.right * 4f * Time.deltaTime);
transform.eulerAngles = new Vector2(0, 180);
}
}
}
void OnCollisionEnter2D(Collision2D other)
{
isDead = true;
anim.SetTrigger("Die");
GameController.instance.GuyDied();
}
}
Comment
Your answer
Follow this Question
Related Questions
Move Character using Finger Gestures for Unity 0 Answers
Rotate GameObject on Touch along Y axis 1 Answer
iOS game "minimizes" if I touch the left side of the screen 0 Answers
iOS Resolutions iPhone and iPad 0 Answers
Iphone as a Web Camera VUFORIA 2 Answers