- Home /
Duplicate Question
help with touch versus keyboard controls
i have a script that can be controle a object by mouse(up,down,right,left) but i need to control object by using touch instead of mouse keyboard?i am new to unity3d
this is my script in this i want to simple camera walk through using andriod
pragma strict
function Start () {
}
function Update () {
//------------------Code for Zooming Out------------
if (Input.GetAxis("Mouse ScrollWheel") <0)
{
if (Camera.main.fieldOfView<=100)
Camera.main.fieldOfView +=2;
if (Camera.main.orthographicSize<=20)
Camera.main.orthographicSize +=0.5;
}
//----------------Code for Zooming In-----------------------
if (Input.GetAxis("Mouse ScrollWheel") > 0)
{
if (Camera.main.fieldOfView>2)
Camera.main.fieldOfView -=2;
if (Camera.main.orthographicSize>=1)
Camera.main.orthographicSize -=0.5;
}
//-------Code to switch camera between Perspective and Orthographic-------- if (Input.GetKeyDown("down"))
{
if(Camera.main.transform.localPosition.x>-3&&Camera.main.transform.localPosition.x<=3){ Camera.main.transform.localPosition.x -=.1; }
}
if (Input.GetKeyDown("up"))
{
if(Camera.main.transform.localPosition.x>=-3&&Camera.main.transform.localPosition.x<3){ Camera.main.transform.localPosition.x +=.1; }
}
if (Input.GetKeyDown("left"))
{ if(Camera.main.transform.localPosition.z>=11&&Camera.main.transform.localPosition.z<16){ Camera.main.transform.localPosition.z +=.1; }
} if (Input.GetKeyDown("right"))
{ if(Camera.main.transform.localPosition.z>11&&Camera.main.transform.localPosition.z<=16){ Camera.main.transform.localPosition.z -=.1; }
}
}
Read this page : http://answers.unity3d.com/page/newuser.html
For any help, please format your code. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.
Watch : http://video.unity3d.com/video/7720450/tutorials-using-unity-answers
Title is too long, Pasted code is not formatted. Question asked 100s of times.
Answer by Graham-Dunnett · Apr 25, 2013 at 03:07 PM
Check out the documentation for advice about using the touch screen on mobile devices. And try this code:
function OnGUI() {
GUI.Label (Rect (10, 10, 100, 35), "Touches");
for (var i : int = 0; i < Input.touchCount; ++i) {
var t : Touch = Input.GetTouch(i);
var p : Vector2 = t.position;
GUI.Label (Rect (10, 35*(i+1), 500, 35), "Touch " + i + ": (" + p.x + ", " + p.y + "){"+ t.fingerId+"}" + t.phase);
}
}
That should allow you to see the touches, their positions etc as you touch the screen.
Follow this Question
Related Questions
unity 5.2 Input.GetTouch(0).position incorrect? 3 Answers
Get Touch touch phase began is grounded not working 2 Answers
Touches, fingerID's and changing them. 1 Answer
Help with iTouch control bug 0 Answers
Why is my Touches array empty? 1 Answer