- Home /
Get current touch position
Hi, I have need touch position, Touch.position dont work.
I dont know why?
#pragma strict
var position: Vector2;
function Start () {
Touch.position = position;
}
function Update () {
}
Error says : An instance of type 'UnityEngine.Touch' is required to access non static member 'position'.
Answer by 767_2 · Sep 27, 2014 at 09:16 AM
var touch: UnityEngine.Touch;
touch.position = position;
sry diffrent error : An instance of type 'UnityEngine.Touch' is required to access non static member 'position'.
now I getting weird error (5,18) UCE0001: ';' expected. Insert a semicolon at the end.
var position: Vector2;
function Start () {
UnityEngine.Touch touch;
touch.position = position;
}
function Update () {
}
Answer by Nexgea · Sep 27, 2014 at 10:36 AM
Ok so I finnaly make it i = Input.GetTouch(0).position;
HUGE thanks for 767_2 for helping me !!!!!
Answer by Wealsegun · Sep 27, 2014 at 12:34 PM
Type this var position: Vector2; function Start () { UnityEngine.Touch touch; touch.position = position; }
function Update () {
}
Answer by TheFloatingSheep · Sep 30, 2014 at 09:29 PM
Something like this?
function Update () {
for (var i = 0; i < Input.touchCount; ++i) {
Touch touch = Input.GetTouch(i);
if (touch.phase == TouchPhase.Began) {
if (touch.position > (Screen.width/2)) {
//do something
}
}
}
}
Your answer
Follow this Question
Related Questions
Double Touch Tap to Select Android 0 Answers
Touch Input for character control using mechanim 0 Answers
Inertia Scrolling Touch 1 Answer
Multi touch not working - What's wrong with this code? 1 Answer