Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Created drag indicator
The drag indicator shows the user roughly how much force will be applied to the planet.
- Loading branch information
Showing
2 changed files
with
57 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.EventSystems; | ||
|
||
public class DragIndicatorController : MonoBehaviour | ||
{ | ||
private new Camera camera; | ||
private Vector2 startPos, endPos; | ||
|
||
private LineRenderer lr; | ||
|
||
// Start is called before the first frame update | ||
void Start() | ||
{ | ||
camera = Camera.main; | ||
lr = gameObject.GetComponent<LineRenderer>(); | ||
startPos = endPos = Vector2.zero; | ||
lr.positionCount = 2; | ||
lr.material.color = Color.black; | ||
lr.enabled = false; | ||
} | ||
|
||
// Update is called once per frame | ||
void Update() | ||
{ | ||
if (!EventSystem.current.IsPointerOverGameObject()) | ||
{ | ||
if (Input.GetMouseButtonDown(0)) | ||
{ | ||
lr.enabled = true; | ||
startPos = camera.ScreenToWorldPoint(Input.mousePosition); | ||
lr.SetPosition(0, startPos); | ||
} | ||
if (Input.GetMouseButton(0)) | ||
{ | ||
endPos = camera.ScreenToWorldPoint(Input.mousePosition); | ||
lr.SetPosition(1, endPos); | ||
} | ||
if (Input.GetMouseButtonUp(0)) | ||
{ | ||
lr.enabled = false; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more.
Oops, something went wrong.