- Home /
Moving the camera on a touch imput
This is pretty basic and I fiddled with it for a while and looked for answers but nothing helped. This is what I came up with so far. The script is attached to the camera along with a box collider2D that moves with it. How would I modify this to have it distinguish between two different colliders? I am unsure how to properly check the tag in this case.
void Update()
{
Vector3 Jester = new Vector3(-8, 0, -10);
Vector3 Knight = new Vector3(8, 0, -10);
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Began)
{
Vector3 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
Vector2 touchPos = new Vector2(wp.x, wp.y);
if (GetComponent<Collider2D>() == Physics2D.OverlapPoint(touchPos))
{
if (Camera.main.gameObject.transform.position == Jester)
{
Camera.main.gameObject.transform.position = Knight;
}
else
{
Camera.main.gameObject.transform.position = Jester;
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Control the camera with a half of the touch screen 0 Answers
How can I fix this Coroutine Camera? 1 Answer
2D Camera (Android, Iphone) 1 Answer
How can I rotate a camera useing 2 touches? 0 Answers
Move to touch position 1 Answer