Skip to content
Permalink
e2e552af54
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
46 lines (42 sloc) 1.22 KB
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;
}
}
}
}