J'ai utiliser ce code sur pc pour quand on cliquait sur un objet et que l'on bougeait la souris, l'objet la suivait.
Maintenant je dois passer mon application sur Ipad mais je n'arrive pas à modifier mon code pour que cela marche.
Quelqu'un peut m'aider?
Merci
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
public class Fonction_Mesure : MonoBehaviour
{
public Vector3 screenSpace;
public Vector3 offset;
//Declaration des spheres
public GameObject Sphere1 ;
public GameObject Sphere2 ;
void OnMouseDown (){
//translate the cubes position from the world to Screen Point
screenSpace = Camera.main.WorldToScreenPoint(transform.localPosition);
//calculate any difference between the cubes world position and the mouses Screen position converted to a world point
offset = transform.localPosition - Camera.main.ScreenToWorldPoint( new Vector2(Input.mousePosition.x,Input.mousePosition.y));
}
/*
OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.
OnMouseDrag is called every frame while the mouse is down.
*/
void OnMouseDrag (){
//keep track of the mouse position
Vector2 curScreenSpace = new Vector2(Input.mousePosition.x,Input.mousePosition.y);
//convert the screen mouse position to world point and adjust with offset
Vector3 curPosition= Camera.main.ScreenToWorldPoint(curScreenSpace) + offset;
//update the position of the object in the world
transform.localPosition = curPosition;
}
}