From e2e552af54a4e3f89965c50aeb45e7bb892d9e11 Mon Sep 17 00:00:00 2001 From: Bartek Wlodarski Date: Sun, 3 May 2020 17:49:01 +0100 Subject: [PATCH] Created drag indicator The drag indicator shows the user roughly how much force will be applied to the planet. --- Assets/Scripts/DragIndicatorController.cs | 46 +++++++++++++++++++ .../Scripts/DragIndicatorController.cs.meta | 11 +++++ 2 files changed, 57 insertions(+) create mode 100644 Assets/Scripts/DragIndicatorController.cs create mode 100644 Assets/Scripts/DragIndicatorController.cs.meta diff --git a/Assets/Scripts/DragIndicatorController.cs b/Assets/Scripts/DragIndicatorController.cs new file mode 100644 index 0000000..d96614c --- /dev/null +++ b/Assets/Scripts/DragIndicatorController.cs @@ -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(); + 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; + } + } + } +} diff --git a/Assets/Scripts/DragIndicatorController.cs.meta b/Assets/Scripts/DragIndicatorController.cs.meta new file mode 100644 index 0000000..890d774 --- /dev/null +++ b/Assets/Scripts/DragIndicatorController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 06cd893d9411f8348babf4599964139d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: