Would like to know if my script it wrong cause it's not working !!

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Drag : MonoBehaviour

//variáveis
private Collider2D drag;
public LayerMask layer;
[SerializeField]
private bool clicked;
private Touch touch;

public LineRenderer linefront;
public LineRenderer lineBack;

void Start()
{
    drag = GetComponent<Collider2D>();
}
   
void Update()
{
    if (Input.touchCount > 0)
    {
        touch = Input.GetTouch(0);

        Vector2 wp = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position);
        RaycastHit2D hit = Physics2D.Raycast(wp, Vector2.zero, Mathf.Infinity, layer.value);

         if (hit.collider != null)
         {
             clicked = true;
         }
         if (clicked)
         {
             if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved)
             {
                 Vector3 tPos = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 10));
                 transform.position = tPos;
             }
         }
         if (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)
         {
             clicked = false;
         }
    }
        //primeira variante
    void SetupLine()
    {
        lineFront.SetPosition(0, lineFront.transform.position);
        lineBack.SetPosition(0, lineBack.transform.position);
    }

    //segunda variante
    void LineUpdate()
    {
        lineFront.SetPosition(1, transform.position);
        lineBack.SetPosition(1, transform.position);
    }


}

How I’d like it to be:

How it is:

Do you have compiler errors? It might be due to how you copied the script, but for example you’re missing the opening curly brace on your monobehaviour class.

1 Like

This is showing up to me :((

So yes, you have compiler errors. You need to fix those first. Such as adding the missing curly brace. Eg:

public class Drag : MonoBehaviour
{ // <- you are missing this
1 Like

Thanks. Now I have only one error.

Don’t tell us! GO FIX IT! Sheesh… kids these days. :slight_smile:

Remember: NOBODY here memorizes error codes. That’s not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

The complete error message contains everything you need to know to fix the error yourself.

The important parts of the error message are:

  • the description of the error itself (google this; you are NEVER the first one!)
  • the file it occurred in (critical!)
  • the line number and character position (the two numbers in parentheses)
  • also possibly useful is the stack trace (all the lines of text in the lower console window)

Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don’t have to stop your progress and fiddle around with the forum.

1 Like

I have fixed the script! Thanks for helping me. :smile:

thank you very much, I fixed it.

1 Like