- Home /
why it is not wrking
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
Rect rectR;
Rect rectL;
Camera camera;
void Start(){
camera=Camera.main;
rectR= new Rect(- Camera.main.orthographicSize * Screen.width / Screen.height, -Camera.main.orthographicSize, Camera.main.orthographicSize * Screen.width / Screen.height, Camera.main.orthographicSize*2);
rectL= new Rect(0,-Camera.main.orthographicSize, Camera.main.orthographicSize * Screen.width / Screen.height, Camera.main.orthographicSize*2);
}
void Update(){
foreach (Touch touch in Input.touches)
{
if(rectR.Contains(touch.position))
{
Debug.Log("testing right side");
}
if(rectL.Contains(touch.position))
{
Debug.Log("testing left side");
}
}
}
what I'm doing wrong !!? the console do not detect any problem but also do not say testing ....
Answer by $$anonymous$$ · Jan 23, 2021 at 03:39 PM
Print out the values of rectR, rectL, and touch.position in Update(). If touch.position is not inside a rect, fix the rect coordinates. If nothing prints, you are not receiving touches.
Answer by unity_GpbWbAdl2iFFOw · Jan 24, 2021 at 08:49 AM
I already checked the position of both rect with drawguismo and I'm sure it is placed where I did need it so I after I searched out I fixed the problem with this way instead of : if(rectR.Contains(touch.position)) ; I write this : if(rectR.Contains(Camera.main.ScreenToWorldPoint(touch.position))) ; and now it is working properly thanks for giving your time ^^
Your answer

Follow this Question
Related Questions
two finger swipe vs pinch and zoom problem 5 Answers
OnGUI().Slider - Alternative 1 Answer
four simultaneous touch inputs in android 2 Answers
multitouch on desktop possible 1 Answer
Problem with UI buttons and MultiTouch 4 Answers