Hi,i’m new with unity and game making. I want to test how to simulate a mobile screen on pc with these simple code:
public class input : MonoBehaviour {
void Update () {
if (Input.touchCount == 1) {
Touch touch = Input.GetTouch(0);
float x = -8f+15*touch.position.x/Screen.width;
float y = -5f+9*touch.position.y/Screen.height;
transform.position=new Vector3(x,y,0);
}
}
}
But i don’t know what is the input devices.Did i need a real phone or something else?
I know that what i’ve asked is silly. But i really hope that you can help me.Thank you.
it is really quite unclear what you are asking here. Do you know that you can setup the screen ratio/size inside the game view of the editor. If you have selected android or iPhone as a target build platform, then there is a dropdown on the game panel that allows you to select pre-existing phone sizes or you can define your own size if you so choose.
As far as the code is concerned, Screen.width and Screen.height will give you the resolution in pixels on the screen no matter what device you will be using.
It does appear that you are trying to move the object this script is attached to to the touch position. I think your confusion might stem from the fact that screen space is not the game world space. if you want to move a 3D object in 3D space to align it with screen space you must first transform the touch position to world space and there is a handy method, Camera.ScreenToWorldPoint(), for that.
Also, you ask if you need an actual phone. You do not need a phone to develop an app in Unity, so no, but you will likely want to test on a phone before launching an app.