K
K
Kot Kotov2020-09-16 20:37:17
Android
Kot Kotov, 2020-09-16 20:37:17

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;
  }
}

In theory, the lines after touching the ball (Player) should fall down and delete. This is how it works, but sometimes there are lines that, after you release the LMB, begin to fall without waiting for the touch of the ball. At the same time, the ball bounces slightly, but the same as if you had drawn a line right under it. Thank you in advance for your help forum members!

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question