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 rednax20 · May 03, 2013 at 12:01 AM · spriteplayclip2dtoolkit

Unity 2d toolkit, play specific clip

I am trying to play a specific clip on input. I want it to change clips, from the idle (it starts out as this clip) to the Begin Run clip. I have a animated sprite with both of these clips included. I think there is a simple syntax for this but I just can't figure it out.

I've tried this code, John is the name of the player object,

 function Update (){
     if(Input.GetKey == "d"){
         player.transform.position += Vector3(forwarddirection, 0,0);
         John.Play    ("Begin Run");
     }
 }

I've tried 2dTK's example for playing specific clips

 function Update (){
     if(Input.GetKey == "d"){
         player.transform.position += Vector3(forwarddirection, 0,0);
             Tk2dAnimatedSprite.Play    ("Begin Run");
     }
 }

I've even tried the name of my animated sprite

 function Update (){
     if(Input.GetKey == "d"){
         player.transform.position += Vector3(forwarddirection, 0,0);
         AnimatedSprite.Play    ("Begin Run");
     }
 }

None of it works. Should I be using a static sprite batcher instead of an animated sprite? please help.

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

Answer by rednax20 · May 14, 2013 at 12:27 AM

I found out my problem. I have to define a variable not just use tk2danimatedsprite. for those that have my problem, I will post this so that you can get help

 var animatedSprite : tk2dAnimatedSprite;
 
 animatedSprite = gameObject.GetComponent(tk2dAnimatedSprite);
 
 animatedSprite.Play("begin run");

I hope this helps, Ithe problem also might have been that I use javaScript, and t2tk uses c. Hope this helps

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 rednax20 · May 23, 2013 at 07:47 PM 0
Share

I forgot to note, you must configure for java script before this will work in java script. That was another problem I had.

avatar image ger122 · Dec 06, 2014 at 12:58 PM 0
Share

hi im having same problem I think

what do u mean define a variable which variable please help

im having troubles and cant figure out

avatar image rednax20 · Dec 07, 2014 at 07:36 PM 0
Share

hello ger, this question was posted over a year and a half ago. I will try to help you as best i can but I may have forgotten a lot of my unity 2d toolkit knowledge.

first off screw everything i said in my question I used to be a complete idiot back then, (judging by what i typed) if your doing that stuff above, don't.

so when you want to play an animation from a sprite you must define the variable for the sprite

 var bazooka : tk2dAnimatedSprite;
  
  bazooka = gameObject.GetComponent(tk2dAnimatedSprite);

essentially this will now represent the animated sprite.

Have you learned how to assign game objects in the inspector? its the same thing but through code. If you want to you can type

 var bazooka : tk2dAnimatedSprite;

and then drag the animated sprite onto this in the inspector. it will do the exact same thing

whenever you type 'bazooka' you are now referencing the sprite and its animations. so now you can type

 bazooka.play("whatever animation you could possibly want");

anywhere in the script and the animation will play, inside a for loop, an if statement, update, whatever.

and remember if you ant to use 2dtk with javascript like this you will have to convert to javascript.

hope this helps, if you need more help i'd be happy to give more assistance, just give me more information if you are still stuck.

and it may take me a while to get back to you, don't worry though, i will eventually get back to you

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

12 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

Related Questions

Noob Question: Play Specific Audio 1 Answer

How to play an animation in reverse? 1 Answer

Sprite Touch and Drag in 2dToolkit 1 Answer

Sprite collor don't change on animation 0 Answers

Audio Clip Plays 1 turn too late 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