Transforms position
from screen space into viewport space.
// When attached to a GUITexture object, this will // move the texture around with the mouse. function Update () { transform.position = Camera.main.ScreenToViewportPoint(Input.mousePosition); }
using UnityEngine; using System.Collections; public class Example : MonoBehaviour { void Update() { transform.position = Camera.main.ScreenToViewportPoint(Input.mousePosition); } }
import UnityEngine import System.Collections public class Example(MonoBehaviour): def Update() as void: transform.position = Camera.main.ScreenToViewportPoint(Input.mousePosition)