I need to be able to click an object in game, and assign a GameObject variable to it, like so:
GameObject Selected;
Selected = (Object Clicked);
But none of the resources I go to seem to work. How do I do this?
I need to be able to click an object in game, and assign a GameObject variable to it, like so:
GameObject Selected;
Selected = (Object Clicked);
But none of the resources I go to seem to work. How do I do this?
Don’t worry about assigning the camera it should work just fine might have forgotten something let me know though
public Camera camera;
public GameObject Selected;
void Start()
{
camera = Camera.main;
}
void OnMouseOver()
{
if(Input.GetMouseButtonDown(0))
{
Ray ray = camera.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray, out hit))
{
hit.collider.gameObject = Selected;
}
}
}