Created
November 14, 2019 11:49
-
-
Save alaingoldman/619cdec273d7caa9561ed88fd1073c72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEngine.EventSystems; | |
// drag tutorial https://www.youtube.com/watch?v=p7akGCRgBLA | |
public class MouseManager : MonoBehaviour { | |
private Vector2 initialPos; | |
private Vector2 mousePointer; | |
private float deltaX, deltaY; | |
private float initScaleX, initScaleY; | |
// private | |
void Start() | |
{ | |
initialPos = transform.position; | |
initScaleX = transform.lossyScale[0]; | |
initScaleY = transform.lossyScale[1]; | |
} | |
// Update is called once per frame | |
void Update() | |
{ | |
} | |
private void OnMouseDown() | |
{ | |
Debug.Log(transform.lossyScale); | |
// float x = transform.lossyScale * 0.3D; | |
transform.localScale = new Vector3(2.1f, 3.15f, 1); | |
// transform.lossyScale = new Vector2(1, 1); | |
// Destroy(GetComponent<Rigidbody>()); | |
} | |
private void OnMouseDrag() | |
{ | |
mousePointer = Camera.main.ScreenToWorldPoint(Input.mousePosition); | |
transform.position = new Vector2(mousePointer.x - deltaX, mousePointer.y - deltaY); | |
} | |
private void OnMouseUp() | |
{ | |
transform.position = new Vector2(initialPos.x, initialPos.y); | |
transform.localScale = new Vector3(initScaleX, initScaleY, 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment