I get a warning (warning CS0472) when I check if a value is null. This is the code I’m using:
BuildingSystem.cs:
using UnityEngine;
using System.Collections;
public class BuildingSystem : MonoBehaviour {
private Vector3 point;
private GameObject selectedObject;
void Start () {
}
void Update () {
if(SelectionSystem.getInWorldPoint() == null) { // warning CS0472
selectedObject = SelectionSystem.getSelection();
} else {
point = SelectionSystem.getInWorldPoint();
}
}
}
SelectionSystem.cs:
using UnityEngine;
using System.Collections;
public class SelectionSystem : MonoBehaviour {
private static RaycastHit hit;
private static GameObject selected = null;
private static Vector3 inWorldPoint = new Vector3(0, 0, 0);
void Start () {
}
void Update () {
Ray ray = camera.ScreenPointToRay(Input.mousePosition);
if(Physics.Raycast(ray, out hit, 500)) {
if(Input.GetKeyDown(KeyCode.Mouse0)) {
if(hit.collider.tag == "Selectable") {
selected = hit.collider.gameObject;
Debug.Log("Selected: " + selected.name);
} else {
selected = null;
inWorldPoint = hit.point;
}
}
}
}
public static GameObject getSelection() {
return selected;
}
public static Vector3 getInWorldPoint() {
return inWorldPoint;
}
}
I get the warning on line 14 in BuildingSystem.cs (Commented in the code).
Warning text:
warning CS0472: The result of comparing value of type UnityEngine.Vector3' with null is false’
I’ve read this, but the value I’m getting an error for is actually changing. Why do I get that error???
/TheDDestroyer12
Thanks! I just found that out. Thanks everyone!
– TheDDestroyer12