distance between 2 objects

Hi,
i’m new to Unity and scripting.
I try to make a simple script to compare distance between two objects: obj_test and player.

Can someone tell me why this doesn’t work? I searched a lot but did not found any answer. Thanks.

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

public class test : MonoBehaviour {
    public GameObject player;
    public GameObject me;
    public float distance;
   
    
    // Use this for initialization
    void Start () {
       
    }
   
    // Update is called once per frame
    void Update () {

        distance = Vector3.Distance(player.transform.position, me.transform.position);

        if (distance >= 10)
        {
            Debug.Log("yo man!");

        }



    }
}

Did you get any error messages in your Console tab? In the inspector, did you drag the appropriate objects into “player” and “me” fields? Did you attach a “test” component to the appropriate object?

1 Like

Oh! I missed the dragging part of the process…
That works just fine now.
Thank you!