Hi.
I’ve been looking all day for an easy way to have a door open by just clicking it, but I haven’t come up with anything that works.
I am a student and I still get quite confused when it comes to C# code, but especially when it comes to Unity itself, I tend to completely lose track of how I’m supposed to do things.
I’ve seen there are numerous ways of doing this:
- Using an animation: I’ve watched this video tutorial, but I can’t get the door out of automatically starting its animation.
- Using normal clicks to simply destroy the door: I got this to work, however it’s not the result I really want, and you’d also have to click the door with your actual mouse, not with the center point of the camera.
- Using Raycasts: this is most likely the way I want it to be done in the end, but the problem is, I don’t understand Raycast, Vector3, Quaternion and those things at all.
Another problem I’ve run into using each one of those methods: I can’t seem to scale the box collider without scaling the entire door. What I’ve done is created the actual body of the door, then created a cube, ticked off the Mesh Renderer component and placed it to the right side of it, where the actual hinges would be. I then made the body a child of this pivot point:
The rotation works the way I want it to, but apparently it’s necessary to scale this cube to cover the entire door, otherwise clicking the door itself won’t work to open it.
So, to sum up:
I’m looking for someone who’d have the time to explain to me how I would have to use Raycasting in order to get a door to rotate -90 degrees on the Y axis, and if it’s necessary, how to scale a cube that’s parent of a door, so that it actually covers said door entirely.
I hope my explanation is clear enough, it’s my first time on this forum, and I’m Belgian, so that should explain any grammatical or spelling errors.
Thanks in advance!