|
Ok, so I read through a bunch of the previous posted questions concerning this topic, but none of them really answered my question.. I'm extremely new to Unity and C#... What I am trying to do is open a door via an animation when the player approaches it. I have the doors already animated, and its under the door object when i expand it. How do I go about writing the right script, and setting up the colliders and what not that is needed? If anyone can help me you'd be a life saver.
(comments are locked)
|
|
may i suggest using java script instead? it's alot easier especially if your new to scripting or you already know actionscript. it may look something like this (assuming you want the door to open and stay open) Bob how would I go about setting up my different pieces to work with that script?
Mar 01 '11 at 12:43 AM
cory
stick the script on an empty game object that has a collider with "is trigger" ticked. Change the bit that says "teapot" to "Player" then tag your character Player in the inspector. Make sure your "door" has an animation on it with "play automatically" unchecked. Highlight the trigger object so it's properties appear in the inspector and drag the "door" gameobject into its script component,there will be a section that says "door Gameobject(none)" with all this set up you should just be able to move your character into the trigger area and it plays the door opening animation
Mar 01 '11 at 02:15 AM
AngryOldMan
(comments are locked)
|
|
Here's a C# script that opens a door. Once it's triggered the script deletes itself. In my case the animation to open the door is named "open". Make sure the In C# (and also in JS) it's the scriptfiles name that have to be equal to the classname. In JS you can omit the class header and JS will automatically inherit from MonoBehaviour.
If you need more complex doors (eg. that closes automatically and so on) that involves a bit more logic in the script. Make yourself familiar with the Unity-api. Unity is very well documented, so take a look at the scripting reference and the runtime classes to understand the concept of Unity. hey I'm sorry, but I typed up the code you gave me, and set up everything the way you said to. Only problem is that I don't have an animatedDoor vairable to drag and drop my door onto
Mar 02 '11 at 03:13 AM
cory
Sorry, had a mistake. In C# inside a class everything is private by default. just add public infront of the fariable. I've changed my answer. Good you've spotted it ;) I didn't tried the sample, just wrote it from scratch.
Mar 02 '11 at 09:54 AM
Bunny83
Fantastic it worked.. You really helped me out big time I needed to get this work for one of my college game design classes. Which is also why I wanted to stick to C# because that is what they're teaching us. I was wondering since you've been so helpful how would I go about making the camera shake, and have a dust particle effect fall from the ceiling?
Mar 03 '11 at 02:31 AM
cory
Well, everything is possible ;) For the particle effect all you need is a particle emitter. To make the particles look like dust you may need to use a particle texture. It could be a lot of try and error to get the right look and feel but it shouldn't be a big problem. Camera shake effects have been asked already just search for it. If you can't find a solution that suits your needs ask another question. But first look here: http://answers.unity3d.com/questions/19559/is-it-possible-to-shake-the-camera
Mar 03 '11 at 02:41 AM
Bunny83
(comments are locked)
|
