- Home /
 
 
               Question by 
               -Orache- · Nov 16, 2016 at 10:50 AM · 
                cameratouchperspective  
              
 
              How can i touch objects in perespective ?
Hi there i want to touch gameobjects in perspective camera . i hear we can use raycast for touch in perspective but i cant work with raycast . . i use this code for all my 2d game (orthographic) :
using UnityEngine; using System.Collections;
public class MenuBtnTouch : MonoBehaviour {
 public Collider2D Coll2D;
 public Vector2 TouchUp;
 
 void Start()
 {
 
     Coll2D = GetComponent<Collider2D>();
     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;
         }
     }
 
 }
 
               }
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
perspective camera into android 0 Answers
i want to help touch functionalities for android how will i do that ?? 0 Answers
Making a camera semi-orthographic 2 Answers
camera smooth follow the targets after touch buttons 0 Answers
Rotate camera smooth on touch 0 Answers