I’m trying to come up with some code to select an object and its not going well. I have 3 problems. They are viewable in the snapshot below. Can someone explain to me what I’m doing wrong??
I will cover the errors:
You are checking for method equality with null. SelectedObject is a method of type void. You actually want to declare a public variable GameObject SelectedObj and set its value upon raycasting.
SelectedObj = hitInfo.transform.gameObject;
For the rest, you have mistaken method for variable. If you create the aforementioned variable, you will be able to control what you want.
You’re checking if your function is null…check if the gameObject is null. Obj.
Hey can you maybe write some of that code or just explain a little more, u mean like declare the variable at the top of the page or just within the group there? I don’t understand sorry i’ve been trying to go back through and fix it and I just don’t get it. Sorry for wasting your time
Something like this
class TheClass
{
private GameObject _selectedObject; // A private variable to hold the currently selected object
public void LefMouseClick()
{
...
if (Pysics.Raycast(...))
{
...
_selectedObject = hitObject;
}
else
{
_selectedObject = null;
}
}
}
OMG THANKS SO MUCH