- Home /
Question by
SaZCoR · Jul 23, 2019 at 05:06 PM ·
animationphysicslinerendererdragging
LineRenderer max lenght
So I'm making a game about something related with minigolf, and i'm making a drag power line, so I used a Line Renderer component, it works well, but i'm trying to find the way to cap the limit of lenght of the line, here's my code; help
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DragIndicatorScript : MonoBehaviour
{
Vector3 startPos;
Vector3 endPos;
Camera cameras;
LineRenderer lr;
public Color startColor = Color.white;
Vector3 camOffset = new Vector3(0, 0, 1);
public Material material;
Renderer rend;
[SerializeField] AnimationCurve ac;
// Start is called before the first frame update
void Start()
{
cameras = Camera.main;
rend = GetComponent<Renderer>();
gameObject.transform.position = new Vector3(0, 0, -1);
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
if (lr == null)
{
lr = gameObject.GetComponent<LineRenderer>();
}
lr.enabled = true;
lr.positionCount = 2;
startPos = cameras.ScreenToWorldPoint(Input.mousePosition) + camOffset;
lr.SetPosition(0, startPos);
lr.useWorldSpace = true;
lr.widthCurve = ac;
lr.numCapVertices = 10;
lr.startColor = startColor;
lr.material = material;
}
if (Input.GetMouseButton(0))
{
endPos = cameras.ScreenToWorldPoint(Input.mousePosition) + camOffset;
lr.SetPosition(1, endPos);
}
if (Input.GetMouseButtonUp(0))
{
lr.enabled = false;
}
}
}
Comment
Your answer
Follow this Question
Related Questions
How does Totally Accurate Battle Simulator's physics and animations work? 0 Answers
how to apply physics to an animated object 1 Answer
Animated line between two points 1 Answer
Can I animate objects/cameras in Update() without breaking Physics.Raycast? 1 Answer
how can i make my character run up ramps like in sonic, fancy pants or even line rider? 1 Answer