hi there
i use this code for touching objects in orthographic but i can use it for perspective !!!
.
using UnityEngine;
using System.Collections;
public class MenuBtnTouch : MonoBehaviour
{
public Collider2D Coll2D;
public Vector2 TouchUp;
void Start()
{
Coll2D = GetComponent();
TouchUp = Vector2.zero;
}
void Update()
{
if (Input.touchCount == 1)
{
Vector3 TouchWorldPosition = Camera.main.WorldToScreenPoint(Input.GetTouch(0).position);
Vector2 TouchPosition = new Vector2(TouchWorldPosition.x, TouchWorldPosition.y);
if (TouchUp == Vector2.zero)
{
TouchUp = TouchPosition;
}
/////////////////////////////////// for change Btns Alpha color
if (Coll2D == Physics2D.OverlapPoint(TouchPosition) && Input.GetTouch(0).phase == TouchPhase.Began)
{
// in touch
}
if (Coll2D != Physics2D.OverlapPoint(TouchPosition))
{
// end touch
}
///////////////////////////////////
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
if (Coll2D == Physics2D.OverlapPoint(TouchUp) && Coll2D == Physics2D.OverlapPoint(TouchPosition))
{
// end touch on object
}
TouchUp = Vector2.zero;
}
}
}
}
my camera is movable (in menu ) and all game objects move with camera (is child of camera ) . all game objects is button for touch and i want to touch it but have problem .
sorry for my bad english