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
0
Question by bobd3000 · Mar 23, 2012 at 07:35 AM · animationvariablesanimation problem

how to declare a animation var

Is it possible to declare an animation variable as follows? var gun_animation : animation

i would like to be able to declare it and be able to call it in a following function. Thanks!

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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by FLASHDENMARK · Mar 23, 2012 at 07:54 AM

 var gun_animation : AnimationClip;

There you go!

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
avatar image
0

Answer by farooqaaa · Mar 23, 2012 at 09:31 AM

Are you talking about Animation component or an AnimationClip?

To declare an Animation component you can use:

 var animationComp : Animation;

 // test use
 animationComp.Play("walk");

If you already have an animation component instance and want to declare an AnimationClip then you can use:

 var walkAnimation : AnimationClip;

 // test use
 animationComp.Play(walkAnimaton.name);
Comment
Add comment · Show 5 · 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 bobd3000 · Mar 23, 2012 at 04:05 PM 0
Share

alright well the way i'm doing it is declaring a animation clip as follows: var reload_animation : AnimationClip;

then calling it in the following statment: function Reload () {

 // Wait for reload time first - then add more bullets!
 yield WaitForSeconds(reloadTime);

 // We have a clip left reload
 if (clips > 0)
 {
 animation.CrossFade(reload_animation);
     clips--;
     bulletsLeft = bulletsPerClip;
 }

}

however no animation slot pops up in the inspector. An alternitive option would be to re-name the animation clip that i have for it so that i can call it. Its current name is Take 001, but my project has multiple animations named Take 001. the prob is i have no idea how to re-name an animation and i really would like this script for ease of use.

avatar image farooqaaa · Mar 23, 2012 at 04:21 PM 0
Share

You forgot to make it public.

Use this:

public var reload_animation : AnimationClip;
avatar image FLASHDENMARK · Mar 23, 2012 at 04:24 PM 0
Share

By default JavaScript/UnityScript variables are public.

avatar image bobd3000 · Mar 23, 2012 at 04:26 PM 0
Share

i get the error: $$anonymous$$ identifire: reload_animation. Also, i made it public but it still does not show up in the inspector. P.S. i'm writing this in java.

avatar image FLASHDENMARK · Mar 23, 2012 at 04:30 PM 0
Share

In order to play an animation from an AnimationClip you will have to use .name:

 animation.CrossFade(reload_animation.name);
avatar image
0

Answer by SterlingStudios · Jul 01, 2014 at 06:11 PM

Why do all that work when you could just use a string?

 #pragma strict
 
 var animationName : String = "";
 var delayTime : float = 1;
 
 function Update () {
 
     Animate();
 }
 
 function Animate () {
 
     yield WaitForSeconds(delayTime);
     animation.Play("" + animationName);
 }
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

6 People are following this question.

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

Related Questions

Continuing movement after animaton on GetButtonUp 0 Answers

Make condition for opening a door (can only be opened when a lever has been activated before) 1 Answer

How do i fix fbx animation import problem from UU3D? 0 Answers

Problem with additive animations 0 Answers

How to get jump animation to play? 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