So I know how to place a prefab based on the mouse position using a ray-cast, but how do I render the mesh in the prefab where the mouse is pointing before I place it on the world?
Also if anyone could tell me how I could make it so I cant place an object if one is already there. Should I use some type of box collier on my prefab attached with a trigger? How do I make the collision perfect and will it cause to much overhead?
just actually spawn the object. move the object so its position is constantly the mouse position and disable collision so it shows up wherever. Make it semi transparent so the player realizes it hasn’t been placed yet as far as the game is concerned.
When the player left clicks detach it and enable collision but first check to ensure nothing is in the way. If something is in the way don’t allow it to detach or anything so they cant get it operating in the game.
perfect collision is done with an arbitrary shape by using a convex mesh collider. It does cause alot of overhead thats why most people don’t make it perfect.
if you would like to know if something is there have a mesh collider or any collider and have it as a trigger not as a normal collider.
now when an object enters the meshs bounds and while it stays there it will set canbuild to false. you can use that bool to stop building.
You need the Ontrigger stay in case multiple objects are involved. you can’t just used ontrigger enter and exit.
for example
object a is inside mesh can build = false;
object b is inside mesh can build = false;
object a leaves the trigger can build = true;
but object b is still in there, so you want the on trigger stay so after the object exits the object b sets canbuild to false again.