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