Skip to content
Permalink
Browse files
Created drag indicator
The drag indicator shows the user roughly how much force will be applied to the planet.
  • Loading branch information
wlodarsb committed May 3, 2020
1 parent b950b27 commit e2e552af54a4e3f89965c50aeb45e7bb892d9e11
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
@@ -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.

0 comments on commit e2e552a

Please sign in to comment.