I’ve created a 3d rectangle (made up of 5 small cubes (1 parent and 4 children)).
When you click on one of the small cubes, the other 5 cubes expand into large cubes.
To do this, I’ll use the following code:
if (mini == 0)
{
temp.x = 1.6f;
temp.y = 1.6f;
temp.z = 1.6f;
transform.localScale = temp;
mini = 1;
}
}
To find out which cube has been clicked, I use the following code:
void Update()
{
if (Input.GetMouseButtonDown(0)) // if I change with (Input.GetMouseButtonUp(0)) it works.
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
if (hit.collider.gameObject == gameObject)
{
Debug.Log("0");
}
else
{
Debug.Log("Cube cliqué : " + hit.collider.gameObject.name);
}
}
}
}
Only when a small cube is clicked, do the small cubes enlarge, but the names of the large cubes are not updated (the names of the cubes in the 3D rectangle are 0, 1, 2, 3 or 4).
Why is the 3D rectangle update perfectly with if (Input.GetMouseButtonUp(0)) and not if (Input.GetMouseButtonDown(0))?
How can I update the large cubes once a small cube has been clicked?
Thanks for your help.
A+