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
2
Question by Ledifen · May 24, 2017 at 06:34 PM · animationtriggerscript.beginnerobjects

[Absolute beginner] Play animation on trigger (trigger = several fallen objects) script

Hello everyone :)

So... I'm an absolute beginner, I don't understand what I find on the internet or I can't adapt it to my situation (or I didn't find it... then I'm very sorry for this post :/ (can you post a link, please ?)

What I want : I have cubes I shoot off platforms. When all the cubes of the scene are down on the floor, I want my animation (just a lift that goes up) to start playing.

I guess the idea is something like "If all components with cube material touch/have touched the floor material ==> playAnimation".

Does anybody know how to script that ? And where do I put that script (I think it's on the lift or on the animation, but I'm not sure) ?

Since I'm new to all of this, I unfortunately need a kind of step by step explanation. I know it's a lot to ask but that would help me greatly.

PS: I understand JS better, but a solution in c# is already perfect.

Thanks a lot :)

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

1 Reply

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

Answer by Ledifen · Aug 12, 2017 at 04:14 PM

In case someone needs this, here's the answer that works for me :

  1. When you have animations in your game, there's a tab next to "Scene", "Game" and "Asset Store" named "Animator". Go there.

  2. Once here, in the window, you must put an arrow (forgot the name) between "Any State" and your animation.

  3. Then, next to the window, you're probably in the "Layers" panel so go to the "Parameters" panel

  4. Click on the + and add a boolean (name it as you want).

  5. Don't check the box (so the boolean = false)

  6. Click on the arrow you created in step 2 and look at the inspector

  7. Somewhere, there's a Conditions tab ==> chose your boolean and set the condition to "true"

alt text


Then, in the script attached to the trigger :

 public int cubeToKnock = 3; // the number of objects (cube) that have to touch the trigger to play the animation
 public Animator animatorLift; //The animator component that holds the animation I want to play
 private int COF = 0; // the variable that counts the objects (cubes) that touch the trigger
         
 
     void Start () {
         animatorLift.enabled = true;
         animatorLift.SetBool("levelFinished", false); //when you have animations in your game, there's a tab next to "Scene", "Game" and "Asset Store" named "Animator". There
     }
 
     void OnTriggerEnter (Collider Cube) {
         if (Cube.gameObject.tag == "cube") {
             COF ++; // each time an object with the cube tag touch the trigger, it adds 1 to COF
         }
     }
     
     void AnimStart() {
         animatorLift.SetBool("levelFinished", true); // a function that sets the value of the boolean you created in you animator window to true when it's called
     }
  
 
     void Update () {
         if (COF == cubeToKnock) {
             Invoke ("AnimStart", 1.5f);  // call the function with a delay of 1 second and a half
         }
     }
 }

There you go. Hope that helps some of you :)

If you have any suggestion to optimize the thing, fell free to share.


anim-explained.png (84.7 kB)
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 Cout_Nico_F · Dec 15, 2020 at 05:21 PM 0
Share

Amazing, thanks ledifen

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

212 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Jump animation not returning to normal? 0 Answers

How can I improve this code? 1 Answer

Simple 2D movement with animation while you are moving 0 Answers

Trigger the Animation #2 after Animation #1 was triggered 0 Answers

Help with a door slam trap 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