1
\$\begingroup\$

I have created a wall using a cube in Unity. Now I want to create a door in it.

How can I make a door in that cube?

Consider that the cube is automatically generated, so i have to generate the door in a C# script.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ While I'm not really happy with the answers, this question is likely a duplicate of this one: gamedev.stackexchange.com/questions/113800/… \$\endgroup\$
    – House
    Commented May 12, 2016 at 18:06
  • 1
    \$\begingroup\$ I think it is not. Please consider that the door has to be auto-generated: so there is a coding part, not only modelling part. \$\endgroup\$
    – EagleOne
    Commented May 12, 2016 at 18:08
  • \$\begingroup\$ The cube mesh is automatically generated? Or it's a prefab with a cube mesh? You need to know how to cut a hole in the cube, and put a door model inside the hole? \$\endgroup\$
    – House
    Commented May 12, 2016 at 18:12
  • \$\begingroup\$ The world itslef is completely autogenerated from code. It has a cube prefab with its cube mesh. Yes, I have to cut the cube and put a door model in it \$\endgroup\$
    – EagleOne
    Commented May 12, 2016 at 18:13
  • \$\begingroup\$ Right, so how is it different from cutting a hole in an existing mesh? Surely you already know how to place the door model once the hole is cut. \$\endgroup\$
    – House
    Commented May 12, 2016 at 18:14

1 Answer 1

1
\$\begingroup\$

Unity primitives are not like actual 3D models, they are great for concepts but do not afford much versatility. I recommend that you start with changing your original wall prefab.

  • Create an empty game object and in it make 3 cubes.
  • Next, arrange the cubes to look like a wall with a space for the door.
  • Make a prefab of this object, maybe name it "wall"

Now make a new cube and size it to fit the hole in the wall. Keep an eye on the transform position in the upper right-hand corner.

You should probably make a prefab of the door object as well.

In C# you'll want to create a "public transform door" this will be visible in the inspector. You can then Instantiate the door at the position you need the door to be. That should look something like:

Instantiate (door, door.position, Quaternion.identity);

In the unity inspector you'll want to drag and drop the door prefab in slot that appears as the door transform.

Hope that helps!

\$\endgroup\$
2
  • 2
    \$\begingroup\$ The moment where one starts building complex objects from cubes and other primitives in the Unity editor is the moment where one should really consider picking up a 3d modeling program. \$\endgroup\$
    – Philipp
    Commented May 13, 2016 at 8:28
  • \$\begingroup\$ @Philipp I upvoted both the question and answer, because this was a problem I had before, and the solution I used. But your comment is the right thing to do. I wish it was a suitable answer. \$\endgroup\$
    – Evorlor
    Commented May 14, 2016 at 5:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .