Instantiation Question

Let's say I have an imaginary cube. If I click on the side of this cube, I want another cube to appear on the side I clicked on one unit away from the cube in that direction. How can this be accomplished?

Thanks, Chad

Assuming you want to use the built-in physics system rather than implementing it manually:

  1. Give the cube a box collider.

  2. Use Camera.ScreenPointToRay() to create a ray corresponding to the current mouse position.

  3. Use Physics.Raycast() to raycast against the cube (or cubes).

  4. If there's a hit:

  5. Compute the position at which to spawn the new object as (e.g.) hitCube.transform.position + hitNormal * cubeSize.

  6. Spawn a new cube at that location.

I think you would need to add a seperate collider for each side of the cube and make them "on trigger" then add a code to each collider to check which side was clicked. there might be a better way of doing it as this is just an idea off the top of my head