#pragma strict
var unitSelected : boolean = false;
function Start ()
{
}
function Update ()
{
var getCoords : Vector3;
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
var currentUnit : Transform = hit.transform;
if(Input.GetMouseButtonDown(0))
{
print(unitSelected + "!!!");
if(unitSelected == true && Physics.Raycast(ray, hit, 1000))
{
currentUnit.transform.position = getCoords;
print("Moved!");
}
if(Physics.Raycast(ray, hit, 1000))
{
currentUnit = hit.transform;
getCoords = Vector3(Mathf.Round(hit.point.x), Mathf.Round(hit.point.y), Mathf.Round(hit.point.z));
print(getCoords);
if(currentUnit != null && currentUnit.tag == "Player 1")
{
print(currentUnit);
unitSelected = true;
}
}
}
}
Can’t seem to understand this. The NullRef is on line 22, I’m guessing currentUnit or getCoords is the culprit here. It is supposed to move the unit to the coordinates of a plane when the player clicks a 2nd time. I’m lost here…