Assigning a vector3?

I am working on an application to measure distances within a model, and I am using raycasts from the mouse click to get the position of the object clicked. (That much does work) However, when I try to assign the values to a vector3, it just returns (-1,-1,-1). Any help please?

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

public class raycastController : MonoBehaviour {

    public bool oneBefore = false;

    void Start() {
       
    }

    void Update() {
        if(Input.GetMouseButtonDown(0)) {
            Vector3 clickPosition = -Vector3.one;
            Vector3 firstPosition = -Vector3.one;

       

            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if(Physics.Raycast(ray, out hit)) {
                clickPosition = hit.point;
            }

            if(oneBefore = false) {
                firstPosition.Set(clickPosition.x,clickPosition.y,clickPosition.z);
            }

            Debug.Log(firstPosition);

            Debug.Log(clickPosition.x+", "+clickPosition.y+", "+clickPosition.z);
        }
    }
}

(-1,-1,-1) is the initiali value you set at line 16. If at line 31 it is unchanged, then it must be your code at line 24 have not executed. You should check if you raycast at line 23 actually hit something or not.

The debug on line 33 does successfully return the value of the hit, so it is hitting.

Discard my previous post, I already see the error. You use = to compare boolean with false, but it should be ==, because single = is assignment operator, it don’t do comparsion.

Btw, usually people do not compare booleans with true and false. Instean, you may write simply

if(myBoolean) {
   // true
}

if(!myBoolean) {
   // false
}

Aah that helped. But it seems to be cutting off after the first decimal point. Is there a way to fix this?

myFloat.ToString(F#)

Instead of # put the number of decimals you want