- Home /
outpost example from unity 3.x Game dev essentials book
I am working on the example specified in the unity 3.x Game Development Essentials Book. I'm stuck with Chapter 5, Approach 3- Trigger collision detection (Page no 179 from pdf). Approach 1 and 2 worked but 3rd doesn't.
Situation: My outpost is similar to the one in the book except that door is not a direct child of the outpost. The hierarchy is
Outpost > Building> Door.
So the way I trigger the door opening animation is
transform.parent.parent.gameObject.animation.Play(animName); I have the triggerZone applied to outpost and DoorManager to the door.
Problem: The door animation does not work with approach 3.
TriggerZone script looks like
void OnTriggerEnter(Collider col){
if(col.gameObject.tag == "Player"){
if(Inventory.charge == 4){
transform.FindChild("building1").FindChild("door").SendMessage("DoorCheck");
if(GameObject.Find("PowerGUI")){
Destroy(GameObject.Find("PowerGUI"));
doorLight.color = Color.green;
}
}else if(Inventory.charge > 0 && Inventory.charge < 4){
textHints.SendMessage("ShowHint","This door won't budge..guess it needs fully charging- maybe more power cells will help...");
transform.FindChild("building1").FindChild("door").SendMessage("DoorCheck");
}else{
transform.FindChild("building1").FindChild("door").audio.PlayOneShot(lockedSound);
col.gameObject.SendMessage("HUDon");
textHints.SendMessage("ShowHint", "This door seems locked.. maybe that generator needs power...");
}
}
}
SendMessage("DoorCheck") successfully calls DoorCheck method in the DoorManager. It also plays the sound (audio.PlayOneShot) but does not play the animation.
void DoorCheck(){
if(!doorIsOpen){
Door(doorOpenSound, true, "dooropen");
}
}
void Door(AudioClip aClip, bool openCheck, string animName){
audio.PlayOneShot(aClip);
doorIsOpen = openCheck;
transform.parent.parent.gameObject.animation.Play(animName);
}
I know the situation is kind of tough to understand because I don't have any errors or warning. The animation which used to work in Approach 1 and 2 does not work in 3. I hope I tried to explain the situation. Please let me know if anybody else had faced the same issue.
I am NOT using unity 3d Pro. I'm using the standard license.
Thanks in advance
Your answer
![](https://koobas.hobune.stream/wayback/20220613120011im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can the animation editor create local rotational data? 3 Answers
Adding animation clips via script 2 Answers
Can I make animations snap to a frame? 1 Answer
How to select an animation clip by index number? 7 Answers
Animation events get lost 1 Answer