- Home /
Question by
awesomeface · Jun 15, 2013 at 11:18 AM ·
javascriptiostouch
touch position
hi, i am quite novice at coding ios/android, anyway, i was hoping someone could tell me how to record the touch position to a variable, hopefully in Vector2 format and in javascript
Comment
Answer by PAHeartBeat · Jun 15, 2013 at 12:32 PM
you can use Input.touches class for it
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
List touchPositions = new List();
void Update() {
if(Input.touchCount > 0) {
touchPositions.Add( Input.touches[0].position)
}
}
you can convert Generic List to Array by using ToArray()
Method of you List Variable
Answer by awesomeface · Jun 16, 2013 at 06:05 AM
i don't understand it completely so could you show me how to do something like this`
var pos1X = 0.0;
var pos1Y = 0.0;
var pos2X = 0.0;
var pos2Y = 0.0;
function Update () {
//pos1X = the x value of the first touch if its x value is (> screen.width * 0.5)
//pos1Y = the y value of the first touch
//pos2X = the x value of the second touch
//pos2Y = the y value of the second touch
}
`
Your answer
![](https://koobas.hobune.stream/wayback/20220613104221im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
android touch input 1 Answer
Unity 2D Mobile Game Drawing Mechanic 0 Answers
Detecting Multiple Touches on same frame IOS 2 Answers
Need Help With Unity iOS "touch" Code 2 Answers