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 benfattino · Jun 17, 2012 at 01:25 PM · animationplay

play animation with script

I try to play animation of an object with a script attached on another object.

 #pragma strict
 
 var OBJ : GameObject; //Object that have animation, script is attached on another object
 var animazione : AnimationClip; //Animation of object
 
 function Start () {
 }
 
 function Update () {
 }
 
 function On_TouchDown(gesture:Gesture){
 OBJ.active = true;
 OBJ.animation.Play("animazione");  
 }

When I play unity say me that not able to found animation.

Comment
Add comment · Show 2
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 thenachotech1113 · Jun 17, 2012 at 02:06 PM 0
Share

are you sure you spelled it correctly, or that you attached the animation component and the animation to this component? because other than that, i don`t know what else could be wrong

avatar image benfattino · Jun 17, 2012 at 02:39 PM 0
Share

I try with this:

var OBJ : GameObject;

var animazione : AnimationClip;

var anim : String;

function Start () { anim = '"'+ animazione.name +'"'; }

function Update () { }

function On_TouchDown(gesture:Gesture){

OBJ.SetActiveRecursively(true);

OBJ.animation.Play(anim);
}

Doesn't work. Work only if I write manually the name of animation ("name") in place of variable anim.

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Grady · Jun 17, 2012 at 02:08 PM

Ok, on your first game object with the animation attached to it, attach this script named "playAnimation":

 function playAnimation(){
     animation.Play();
 }

Then on your second game object, attach this:

 var animatedObject : GameObject;
 
 function On_TouchDown(gesture:Gesture){
         animatedObject.GetComponent(playAnimation).playAnimation();
 }

This should work, if it doesn't, then comment back! I'm not at unity right now, so I haven't been able to test it, but it should give you some idea!!!!!

-Grady

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 slayer29179 · Jun 17, 2012 at 02:09 PM

I think I may have the answer: what have you called the animation on your character? your script (if I am right) is searching on the game Object OBJ for an animation called animazione try getting rid of the speech marks to link it to that animation variable like so;

 OBJ.animation.Play(animazione); 

hope this helps!

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 benfattino · Jun 17, 2012 at 02:42 PM 0
Share

Try. Nothing.

avatar image
0

Answer by aldonaletto · Jun 17, 2012 at 02:15 PM

I suspect you're confusing things: you must pass the animation clip name to OBJ.animation.Play - like this:

 OBJ.animation.Play("idle");

This will play the clip called "idle". If you want it to repeat forever, set the wrap mode:

 OBJ.animation["idle"].wrapMode = WrapMode.Loop;
 OBJ.animation.Play("idle");

Check what's the clip name of the animation you're interested in.

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 benfattino · Jun 27, 2012 at 11:37 AM

I try this script without result. Unity say me that can't found animation.

 #pragma strict
 
 var OBJ : GameObject;
 var SingleTouch : boolean = true;
 var DoubleTap : boolean = false;
 var Swipe : boolean = false;
 var animazione : AnimationClip;
 var anim : String;
 
 function Start () {
 anim = '"'+ animazione.name +'"';
 }
 
 function Update () {
 
 }
 
 function On_TouchStart(gesture:Gesture){
 if (SingleTouch){
 OBJ.SetActiveRecursively(true);
 OBJ.animation.Play(anim);  
 }
 }
 
 function On_DoubleTap(gesture:Gesture){
 if (DoubleTap){
 OBJ.SetActiveRecursively(true);
 OBJ.animation.Play(anim);  
 }
 }
 
 function On_SwipeStart(gesture:Gesture){
 if (Swipe){
 OBJ.SetActiveRecursively(true);
 OBJ.animation.Play(anim);  
 }
 }

Somebody help me?

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 aeldron · Aug 12, 2013 at 12:13 PM 0
Share

@benfattino I know this is a really old thread but I've just spotted your mistake.

You should simply write: anim = animazione.name;

If you do '"'+ animazione.name +'"' you're adding quotes to the string literal. That won't work unless the quotes are part of your animation clip name (I suspect they are not?).

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

8 People are following this question.

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

Related Questions

what is the jump axis for if (Input.GetAxis(" ? ") 2 Answers

Animation play error. No animation attached. 3 Answers

animating objects, end position changes 1 Answer

Play animation from script in Unity 4.3 0 Answers

Play animation when in collider and button pressed 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