iOS moving up and down question ( code problem )
So i want to make an iOS game ... for now i just want to make it move up and down ... the problem is with the touching,i dont quite understand how touches work . If i keep my finger on the screen it will just move up and down around the same spot and sometimes when i touch the screen it will just move up a little ( or down ) and then it continues back down ( or up ) , meaning it doesnt change its direction ( so lets say it is moving up,it changes the direction for 0.1 seconds down and then it continues up again , it changes its direction just for 0.1 seconds basically ).I don't quite uderstand what touch phase is but i guess i need to use that Here is the code :
using UnityEngine;
using System.Collections;
public class Miscare : MonoBehaviour {
public float speed = 120.0f;
private Rigidbody2D myRigidbody;
private int movement = 1;
private int touch = 0;
// Use this for initialization
void Start () {
myRigidbody = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
foreach (Touch touch in Input.touches)
{
if (movement == 1 & touch == 0)
{
myRigidbody.AddForce(Vector2.up * speed);
movement = 0;
touch = 1;
}
if (movement == 1 & touch == 1)
{
myRigidbody.AddForce(-Vector2.down * speed);
myRigidbody.AddForce(Vector2.up * speed);
movement = 0;
}
else
if (movement == 0 & touch == 1)
{
myRigidbody.AddForce(-Vector2.up * speed);
myRigidbody.AddForce(Vector2.down * speed);
movement = 1;
}
}
}
}
Help please,maybe rewrite it if you can,or just explain me what should i do. The code for moving is good cause i made this game on PC and it worked,the problem is with the touches ... on PC was easier cause you had to press a key.