Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by alexnode · Mar 26, 2010 at 11:29 AM · animationbeginnerhierarchydoorsimplify

Begginers question, Simplifing a script, opening two doors with 2 overlapping triggers.

I have the script below that works but it seems too big and unnecessary for the task. I have two rotating "sliding doors" that play with animation from .max file. I don't want to combine the doors to one because they use different materials that are repeated all over the project. I put two overlapping triggers to open them when you approach with the default first person controller.

The triggers are children of the parent animated object because I though that searching by tag or name will be slower. They play the animation with "gameObject.transform.parent...." is that a correct approach ? If I use one trigger I'll have to find the objects by tag and when you have many instances of these tags it seems that things are becoming a bit random on what door is opening. When I do the artwork (yes I am one of those ) I put an empty box called triggerXXX in my model and if I have multiple animations in one file I put multiple triggers as children. I do that because it is faster than snapping in unity and because I don't want to brake the connection with the original models which fills me with metaphysical fear !!! ... of assigning all the layers,the tags, the triggers and the materials again in a later stage. So as a strategy what is the most elegant way of assigning triggers that can work on multiple different objects?

//I duplicated my initial variables to triggerS and triggerT to avoid conflict//

private var triggerSActivated : boolean = false; private var triggerTActivated : boolean = false; private var timerS : float = 0.0; private var timerT : float = 0.0; private var triggerSObject : GameObject; private var triggerTObject : GameObject; var doorOpenSound : AudioClip; var doorShutSound : AudioClip;

function OnTriggerEnter (hit:Collider){ if((hit.gameObject.tag == "lifttrig_s") && (triggerSActivated == false)){ triggerSObject=hit.gameObject ; print (triggerSObject.name);

 doorsS (doorOpenSound,"dooropen", triggerSObject,true);
 }

 if((hit.gameObject.tag == "lifttrig_t") && (triggerTActivated == false)){
  triggerTObject=hit.gameObject ;
  print (triggerTObject.name);

 doorsT (doorOpenSound,"dooropen", triggerTObject,true);
 }

 }

function Update() {

 if(triggerSActivated) 

 {
     timerS += Time.deltaTime;
 }

 if(timerS >= 5)

 {
     doorsS(doorShutSound, "doorshuts", triggerSObject, false);      
      timerS = 0.0;  
 }

 if(triggerTActivated) 

 {
     timerT += Time.deltaTime;
 }

 if(timerT >= 5)

 {
     doorsT(doorShutSound, "doorshuts", triggerTObject, false);      
      timerT = 0.0;  
 }

}

function doorsT (aClip: AudioClip ,animName : String, aniTObject :GameObject, triggerTCheck: boolean) { audio.PlayOneShot(aClip); triggerTActivated = triggerTCheck;

aniTObject.transform.parent.animation.Play(animName); }

function doorsS (aClip: AudioClip ,animName : String, aniSObject :GameObject, triggerSCheck: boolean) { audio.PlayOneShot(aClip); triggerSActivated = triggerSCheck;

aniSObject.transform.parent.animation.Play(animName);

} @script RequireComponent(AudioSource)

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image duck ♦♦ · Mar 26, 2010 at 12:47 PM 0
Share

What do the "S" and "T" suffixes mean?

avatar image alexnode · Mar 30, 2010 at 08:46 AM 0
Share

It is solid and transparent but you can treat them as Left and Right.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by alexnode · Apr 05, 2010 at 04:39 PM

Dump!! me, sorry, I just had to store the animation on the root object, and have only one trigger that plays all the door animations. I separated the model with the different animation (Lift in my case) to another model so that the root gameObject doesn't play the lift animation too. the code looks much better now.

private var doorIsOpen : boolean = false; private var timer : float = 0.0; private var doorObject : GameObject;

var doorOpenSound : AudioClip; var doorShutSound : AudioClip;

function OnTriggerEnter (hit:Collider) { if((hit.gameObject.tag == "doorani") && (doorIsOpen == false)){ doorObject=hit.gameObject ; doors (doorOpenSound,"dooropen", doorObject,true);

 }

}

function Update() {

 if(doorIsOpen) 

 {
     timer += Time.deltaTime;
 }

 if(timer >= 6)

 {
     doors(doorShutSound, "doorshuts", doorObject, false);       
     timer = 0.0;    
 }

}

function doors (aClip: AudioClip ,animName : String, doorObject :GameObject, doorCheck: boolean) {

audio.PlayOneShot(aClip); doorObject.transform.parent.animation.Play(animName); doorIsOpen = doorCheck;

} @script RequireComponent(AudioSource)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Opening multiple doors with the same animation 1 Answer

Respawn script and door animation help 0 Answers

Rotation Y axis is bugged. 2 Answers

door animation physics 1 Answer

Created an Open Close Animation, but script wont activate both doors? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges