Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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
1
Question by kez717 · Jan 16, 2010 at 12:01 PM · animationcharacterrandom

random animations

how can i have animations randomly play? for example i have 2 idle animations, one main and one that i would like to play once through at random intervals while the character is not moving. how would i go about getting this to happen? so far i can only get the main idle animation to play.

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
2
Best Answer

Answer by duck · Jan 16, 2010 at 02:41 PM

perhaps your idle animation could be controlled by a coroutine, something like this:

function Idle()
{
    while (idling) {
        if (Random.Range(0,5) > 0) {
            animation.Play(idleClipNormal);
            yield WaitForSeconds (idleClipNormal.length);
        } else {
            animation.Play(idleClipOccasional);
            yield WaitForSeconds (idleClipOccasional.length);
        }
    }
}
Comment
Add comment · Show 2 · 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 kez717 · Jan 17, 2010 at 11:48 AM 0
Share

how would i implement something like that? can barely muck through the demo scripts and patch together something that sort of works, i havent much of a clue when it comes to adding something along these lines.

avatar image duck ♦♦ · Jan 17, 2010 at 12:12 PM 0
Share

the above code assumes that you would call the function Idle() when the character should start idling. You should also have a boolean variable called 'idling' which is set to true. The function above will keep playing idle animations until you set the 'idling' boolean variable to false.

avatar image
1

Answer by eurosat7 · Mar 01, 2010 at 05:23 PM

This is what I did:

var SceletorObject : GameObject = null; var curAnim : String = null; var doAnimation : boolean = false; private var AnimObj : Animation = null;

function Start(){ AnimObj=SceletorObject.GetComponent(Animation); }

function OnTriggerEnter() { AnimObj.PlayQueued("raise"); doAnimation=true; } function OnTriggerExit() { AnimObj.PlayQueued("hit"); AnimObj.PlayQueued("die"); doAnimation=false; } function OnTriggerStay(){ if (!AnimObj.isPlaying && doAnimation) doNextAnim(); } function doNextAnim(){ var anims=new Array("idle1","idle1","idle1","idle1","idle2","strike"); var length=anims.length-1; var index=Mathf.Round(length*UnityEngine.Random.value); curAnim=anims[index]; AnimObj.PlayQueued(curAnim); }

HTH

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

Random location when clicked on 1 Answer

FPSInputController and Character Animation 1 Answer

Character animation problem 1 Answer

Characters Interaction with Mecanim Animations 2 Answers

Root motion / How to bake into pose Root Transform Position (x) 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