Vector3.Distance does not work

hi i need help trying to create a list on transform [ ] but it doesn’t work for me on vector3.distance it says “error CS0103: The name ‘position’ does not exist in the current context”,I don’t want to put all the code here.what with this? thank you

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

public class crowbar1 : MonoBehaviour
{
    public Transform[] glue;
    
  
    private void OnDrawGizmosSelected()
    {
        Gizmos.color = Color.green;
        Gizmos.DrawSphere(transform.position, radius);
    }
    public void Update()
    {
       
        float distanceGlue = Vector3.Distance(glue,position,transform.position);

I suppose you wanted to put a dot between glue & position:
Vector3.Distance(glue.position, transform.position) ?
The way you’ve put it in your code it looks like you passed 3 parameters there. Aside from that, glue is an array and you can’t use it like that, you should have something like glue[0].position etc… But as you said it’s just an example code, I’ll leave that to you…

1 Like

thank you very much :smile:

Anytime you say “feature X doesn’t work” and that feature is a core part of a game engine used by MILLIONS of people around the world, that’s your clue to think “Maybe I don’t understand something” and go STRAIGHT to the documentation to read how to use Vector3.Distance();

Besides, 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.

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.

1 Like