-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ee60aa
commit 3df3db6
Showing
220 changed files
with
60,063 additions
and
11 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class DragObject : MonoBehaviour | ||
|
||
{ | ||
private Vector3 mOffset; | ||
private float mZCoord; | ||
void OnMouseDown() | ||
{ | ||
mZCoord = Camera.main.WorldToScreenPoint( | ||
|
||
gameObject.transform.position).z; | ||
|
||
// Store offset = gameobject world pos - mouse world pos | ||
|
||
mOffset = gameObject.transform.position - GetMouseAsWorldPoint(); | ||
} | ||
|
||
private Vector3 GetMouseAsWorldPoint() | ||
{ | ||
// Pixel coordinates of mouse (x,y) | ||
Vector3 mousePoint = Input.mousePosition; | ||
|
||
// z coordinate of game object on screen | ||
mousePoint.z = mZCoord; | ||
|
||
// Convert it to world points | ||
return Camera.main.ScreenToWorldPoint(mousePoint); | ||
} | ||
|
||
void OnMouseDrag() | ||
{ | ||
transform.position = GetMouseAsWorldPoint() + mOffset; | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.