- Home /
Touch Hd screen drag problems
Hi!
I have a problem. When I use a typical dragging script (drag and rotates a gameobject) it works fine with my pc and in Android too, but when I use the exe in a touch hd screen the dragging doesn't work. Why it happens?
check by yourself, why it works only in andrid touches and with windows mouse?:
..............................................................
using UnityEngine; using System.Collections;
public class drager : MonoBehaviour {
private bool dragging = false;
private float distance;
void OnMouseDown()
{
distance = Vector3.Distance(transform.position , Camera.main.transform.position);
dragging = true;
}
void OnMouseUp()
{
dragging = false;
}
void Update()
{
if (dragging)
{
float distance_to_screen = Camera.main.WorldToScreenPoint(gameObject.transform.position).z;
Vector3 pos_move = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance_to_screen ));
transform.position = new Vector3( pos_move.x, pos_move.y, pos_move.z );
}
}
}
Your answer
Follow this Question
Related Questions
Jump when touch the screen Android (GAME MADE FOR PC) 5 Answers
How do I rotate an object on one axis to face android touch? 0 Answers
Android clear touch queue 0 Answers
How to make a character move towards a side of the screen that's pressed at a constant rate? 2 Answers
touch position to world position 2D 2 Answers