I want to make object stopped when it hit collider of another object.
But it doesn't stop. How can I fix this? - Unity
my code is:
public class move: MonoBehaviour {
public float speed = 0.5f;
// Update is called once per frame
void Update () {
if (Input.touchCount ==1)
{
Touch touch = Input.GetTouch(0);
float x = -7.5f + 15 * touch.position.x / Screen.width;
float y = -2;
transform.position = new Vector2(x * speed, y);
}
}
}