Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Richardfalcos · Apr 30, 2016 at 11:00 PM · animationerror

Two animations to a single gameObject

Hi, I have two animations, with the names "open" and "closed" would when entering the trigger animation to begin with the name "Open" and when you leave the trigger animation to begin with the "closed" name. I have the following script that works very well for "open" someone could help me out when the trigger the animation named "closed" start? Below is my script, I tried to put a variable, but it did not work. help me

 #pragma strict
 
 //var ani1 : Animator;
 var ani : Animator;
 var sound : AudioClip;
 
 function Start () {
     ani.enabled = false;
 }
 
 function OnTriggerEnter () {
 
     AudioSource.PlayClipAtPoint (sound, transform.position);
     ani.enabled = true;
 
     //Destroy(gameObject);
 }
 
 
 /*
 function OnTriggerExit () {
     AudioSource.PlayClipAtPoint (sound, transform.position);
     ani1.enabled = true;
     //Destroy(gameObject);
 }
 */
 

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by incorrect · Apr 30, 2016 at 11:09 PM

You'd better try getting deep into the learning section about Animation. You just switch on an animator component instead of controlling it.

Usually you would handle it like this:

 function OnTriggerEnter () {
     ani.SetTrigger("open");
 }
 
 function OnTriggerExit () {
     ani.SetTrigger("close");
 }

Of course you need to properly setup your animator controller to handle those triggers and transitions based on them.

Transitions and conditions are explained in Animator Controller video tutorial.

Comment
Add comment · Show 1 · 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
avatar image Richardfalcos · May 01, 2016 at 04:03 AM 0
Share

Obrigado, vou tentar aprender um pouco mais...

avatar image
0

Answer by Richardfalcos · May 01, 2016 at 03:05 PM

I needed the help of friends, to open and close a door with two animations, was not able to animator, because I could not make the Player open the door when entered the trigger and leave when she left. So I otherwise without animation control. Who is interested here what I got and it worked perfectly.

 var  chestSound: AudioClip; // peito abertura clipe de som vai aqui
 var  treasureChest: GameObject; // pré-fabricada arca do tesouro vai aqui
 var  treasureChest2: GameObject;
 function  OnTriggerEnter (col: Collider) 
 {
  
 if (col.gameObject.tag == "Player" )
  
         { // verifica para ver que o nosso controlador de personagem com tag "Player" entrou no gatilho
         AudioSource.PlayClipAtPoint (chestSound, transform.position); // toca o nosso clipe de som na posição do colisor / gatilho
         treasureChest.GetComponent.<Animation>().Play ("box_open"); // reproduz a animação padrão aplicado ao nosso modelo treasurechest
         //Destroy (gameObject); // destrói o GameObject que tem esse script, então o nosso colisor, neste caso,
          }
 }
 
 function  OnTriggerExit (col: Collider) 
 {
  
 if (col.gameObject.tag == "Player" )
  
         { // verifica para ver que o nosso controlador de personagem com tag "Player" SAIU no gatilho
         AudioSource.PlayClipAtPoint (chestSound, transform.position); // toca o nosso clipe de som na posição do colisor / gatilho
         treasureChest2.GetComponent.<Animation>().Play ("box_close"); // reproduz a animação padrão aplicado ao nosso modelo treasurechest
         //Destroy (gameObject); // destrói o GameObject que tem esse script, então o nosso colisor, neste caso,
          }
 }
 
Comment
Add comment · Show 1 · 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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

The name animator does not exist in the current context... Help? 1 Answer

Door control coordinates being a jerk 0 Answers

Getting this error:BCE0020: An instance of type 'UnityEngine.Animation' is required to access non static member 'Play'. 1 Answer

CrossFade won't crossfade animation, it just jumps to it. 0 Answers

Unity, Mechanim And Mixamo 3D Animation: NullReferenceException. 0 Answers


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