|
I am completely new to scripting. I am not familiar with a lot of the syntax, however I am familiar with some basic coding. This is what I need to accomplish, but have no idea how to approach it: The player unlocks a door after investigating 5 different clues. The clues have sphere colliders on then that pops up informative text whenever the player enters the collider, then disappears when they back away from the clue. like this:
I need to make it so after the player has entered all 6 of the "clue spheres" at least once that a "Door Open" animation is played on an object in my scene (I have made the door animation already). The player can then pass through the open door. So how do I code it so that the script keeps track of if all the clues that have been "entered", and then plays the animation when all of them have been investigated? Any help is greatly appreciated! :)
(comments are locked)
|
|
I would make the clues script itself handle this, and use a simple static counter variable to count the number of clues remaining to be found. Here is the modified script - only a few lines added: Hi Duck, I added the script to all the clues, but I'm getting the error message "Missing Component Exception: There is no animation attached to the game object, but a script is trying to access it." The animation is attached to the door, I don't know how to tell the script to play the animation on the door game object. :(
May 10 '10 at 11:43 PM
sybrix
(comments are locked)
|
|
One method is to keep an array of clues found and then opening the door when the length of the array is greater than 4 or something. You can search the array to make sure that the clue isn't already in it and then use the Array.Push method to add a clue id onto the array. e.g.
Alternatively if there are only a few clues in a place you can use boolean values associated with each clue and only open the door when all clues are set to true. e.g.
(comments are locked)
|
|
The last sample tells the collider that triggers the event IS the First Person Controller, so it searches an animation in it, but I figure you already know that by this time, don't you ? Instead of using the "other" object, use the door object.
(comments are locked)
|
|
Okay here's the code I got so far:
I have the other GameObject var set to the Door in the Inspector for all of the clues, however when I walk into a clue I get the error "Missing Component Exception: There is no animation attached to the "First Person Controller" game object, but a script is trying to access it." I am completely baffled as to why the script is looking for animation on the FP controller.
(comments are locked)
|
