Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
2
Question by phatpixels · Jun 01, 2014 at 07:22 AM · playrandom.rangecountercount

counting how many times a specific animation plays

Hello u unity users. How would you count how many times a specific animation plays from a random range of animations? In this case I want "swing" to play 5 Times, // then do something.

("Roll","spin","swing")

Comment
Add comment · Show 5
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 phatpixels · Jun 01, 2014 at 12:18 PM 0
Share

I tried your script, although it works,it just counts as fast as the random range generates its numbers. What I really need is to have a count for every time the specific animation plays. Any thoughts?

avatar image thornekey · Jun 01, 2014 at 12:27 PM 0
Share

if (animation.Play(ur specific animation)) { counter +=1; }

avatar image phatpixels · Jun 01, 2014 at 01:21 PM 0
Share

Again your script works just fine.but same result, counter just keeps counting quicker than actual animations play. I think the issue is that random.range generates queued animations ahead of time and just keeps generating a massive queue and counts+1 as it climbs. Is this possible? I'm a bit out of my depth I think.

avatar image thornekey · Jun 01, 2014 at 01:24 PM 0
Share

can i see ur whole script?

avatar image phatpixels · Jun 01, 2014 at 01:43 PM 0
Share
 #pragma strict
 #pragma downcast
 
 var Anims = ["up","down"];
 var $$anonymous$$odel: GameObject;
 var speed =3;
 var count : int;
 
 
 
 
 function Update () {
 
  Game();
 }
 
 
 
 function Game () {
 
 var random:int = Random.Range(0,2);
 
 if (random ==0){
 
 animation.CrossFadeQueued("up");
 count+=1;
 
 }
 
 
 
 if (random ==1){
 
 animation.CrossFadeQueued("down");
 }
 }
 
 

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by thornekey · Jun 01, 2014 at 07:25 AM

you could have an int counter so after ever time the animation plays add one value to it like so:

 public int counter = 0;


 animation.Play(playur animation);
 counter +=1;

 or for a specific animation

 if (animation.Play(ur specific animation)) { 
 counter +=1; 
 }
 
 if(counter >= 5) {
 //do ur thing
 //reset the counter
 counter == 0;
 }
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 Xx_Alanox_xX · Oct 21, 2017 at 06:06 PM 0
Share

How can you get the animation ? When i enter animation.Play($$anonymous$$yAnim) it doesn't find the path to the specific animation...

avatar image
-1

Answer by sarusian · Jun 01, 2014 at 12:57 PM

     public int counter = 0;
      
      
     animation.Play();
     if (animation.Play(theAnimation) {
 counter += 1;
 }
      
      
     if(counter >= 5) {
     //do ur thing
     //reset the counter
     counter == 0;
     }
Comment
Add comment · Show 3 · 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 thornekey · Jun 01, 2014 at 12:58 PM 0
Share

thats my answer.. u just copied it lol

avatar image sarusian · Jun 01, 2014 at 01:07 PM 0
Share

I answered first, It was submitted for approval, this system is so stupid, I have to wait until I get enough $$anonymous$$arma, and if someone answers others downvote for copying and a loose karma, its a vicious cycle.

avatar image thornekey · Jun 01, 2014 at 01:16 PM 0
Share

you are such a liar. ive highlighted a certain thing called a time stamp in red.. -.-

LOO$$anonymous$$ AT THE TI$$anonymous$$E I ANSWERED 5 HOURS AGO. And your text is EXACTLY the same. Ive reported you.

alt text

you are pathetic.

picture 8.png (90.0 kB)
avatar image
0

Answer by Xx_Alanox_xX · Oct 21, 2017 at 06:04 PM

He even forgot to close the "()" x), thank you thorney !

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

24 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

Related Questions

Collision counter 2 Answers

How to count instantiated objects that passes a given point (transform.position.y) 1 Answer

Randomising list of integers and removing them from list once the task assigned to the integer in the project is completed 0 Answers

count the number on enemyes entrering into a trigger 1 Answer

I created a system that tracks number of matches have 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