I have a car and wan’t to open it’s hood when I mouse over it and click left mouse button, I got something like this done, but it doesn’t seem to be working…
code:
void Update()
{
Ray ray = cam.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray,out hit))
{
if (hit.collider == hod && (Input.GetMouseButtonDown(0)) && open == false) {
hood.SetActive(false);
open = true;
}
if (hit.collider == hod && (Input.GetMouseButtonDown(0)) && open == true)
{
hood.SetActive(true);
open = false;
}
}
}