Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- public class MousePointer : MonoBehaviour
- {
- private Vector2 mouseDownStart;
- private Vector3 objectStart;
- private Vector2 mouseDelta;
- private bool dragging = false;
- public float pixelWorldRatio;
- void Update ( )
- {
- if ( Input.GetMouseButtonDown ( 0 ) )
- {
- mouseDownStart = Input.mousePosition;
- mouseDelta = Vector2.zero;
- objectStart = transform.localPosition;
- dragging = true;
- }
- if ( Input.GetMouseButtonUp ( 0 ) )
- {
- mouseDelta = Vector2.zero;
- dragging = false;
- }
- if ( dragging )
- {
- mouseDelta = ( Vector2 ) Input.mousePosition - mouseDownStart;
- gameObject.transform.localPosition = new Vector3 ( objectStart.x + ( mouseDelta.x * pixelWorldRatio ), objectStart.y, objectStart.z + ( mouseDelta.y * pixelWorldRatio ) );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment