Answer the question
In order to leave comments, you need to log in
How to fix unity false positives (I hope so)?
We have the code from this video https://www.youtube.com/watch?v=dmBQQ2XtuhU , well, how is the code... 2 scripts for drawing a line. One rushes to the line (the whole problem is in it), the other rushes to an empty object to track clicks.
I slightly modified the code from the Line.cs file
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
public class Line : MonoBehaviour
{
public LineRenderer lineRenderer;
public EdgeCollider2D edgeCol;
List<Vector2> points;
private int TimeToDestroy = 5;
public int droppedSpeed;
private bool drop = false;
private void Start()
{
Destroy(gameObject,TimeToDestroy);
}
private void FixedUpdate()
{
if(drop)
dropLine();
}
public void dropLine()
{
transform.position -= new Vector3(0, 6 * Time.deltaTime, 0);
if (transform.position.y<-6f)
{
Destroy(gameObject);
}
}
public void UpdateLine(Vector2 mousePos)
{
if (points == null)
{
points = new List<Vector2>();
SetPoint(mousePos);
return;
}
if (Vector2.Distance(points.Last(), mousePos) > .1f)
SetPoint(mousePos);
}
void SetPoint(Vector2 point)
{
points.Add(point);
lineRenderer.positionCount = points.Count;
lineRenderer.SetPosition(points.Count - 1, point);
if (points.Count > 1)
edgeCol.points = points.ToArray();
}
private void OnCollisionEnter2D(Collision2D collision)
{
if (collision.gameObject.tag == "Player")
drop = true;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question