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 loon · Sep 29, 2012 at 08:05 AM · animation2dplayorthello

(Solved) Cannot play animation in Orthello outside start()

The animation (mySprite) does not play in the update function or it's calls. It only plays inside the start function.

a) mySprite is shown as 'OTAnimatingSprite' object in all functions, performed Debug.log(mySprite). b) It's memory intensive, but still tried moving

 mySprite = this.GetComponent<OTAnimatingSprite>();

inside the other function in which I do

 mySprite.Play("runRight");

This does not work.

My Code:

 using UnityEngine;
 using System.Collections;
 
 public class Player : MonoBehaviour {
     public OTAnimatingSprite mySprite;
 
     public static bool isLeft;
     public static bool isRight;
     public static bool isUp;
     public static bool isDown;
     /* ============================== CONTROLS ============================== */
     
     // Use this for initialization
     void Start () 
     {
         mySprite = this.GetComponent<OTAnimatingSprite>();
         Debug.Log("Player Script Started: " + mySprite);
         mySprite.Play("runRight");
     }
     
     private void updatePlayerMovement() {
         //moveRight();
         //moveLeft();
         
         //moveUp();
         this.moveRight();
     }
     
     private void moveUp() {
         this.transform.Translate(Vector3.up * Time.deltaTime*30, Space.World);
     }
     private void moveDown() {
         this.transform.Translate(Vector3.down * Time.deltaTime*30, Space.World);
     }
     private void moveLeft() {
         this.transform.Translate(Vector3.left * Time.deltaTime*30, Space.World);
     }
     private void moveRight() {
         this.transform.Translate(Vector3.right * Time.deltaTime*30, Space.World);
     }
     public void Update () {
         
         // these are false unless one of keys is pressed
         isLeft = false;
         isRight = false;
         isUp = false;
         isDown = false;
 
         // keyboard input
         if(Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) 
         { 
             isLeft = true; 
             Debug.Log("Left: " + mySprite);
         }
         if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) 
         { 
             isRight = true; 
             Debug.Log("Right!");
         }
 
         if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) 
         { 
             isUp = true;
             Debug.Log("Up");
         }
         if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) 
         { 
             isDown = true; 
             Debug.Log("Down!");
         }
         updatePlayerMovement();
     }
 }
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
1

Answer by mas · Sep 29, 2012 at 12:24 PM

Would be a good thing to provide us with the exact code that does not work because I do not see any mySprite.Play(..) in the Update() function.

however ...

Asuming that the code that does not work in the Update would look a bit like :

 if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) 
            { 
              isRight = true; 
              mySprite.Play("runRight")
            }
 

I can confirm that this will not work because by calling mySprite.Play you are restarting the animation, each update cycle, while your D or rightArrow key is pressed.

Better would be something like

     if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) 
                { 
                  isRight = true;
                  if (mySprite.animationFrameset!="runRight") 
                      mySprite.Play("runRight")
                }
 
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 shaderop · Sep 29, 2012 at 02:45 PM 0
Share

+1 for a great first answer. Welcome aboard!

avatar image loon · Sep 29, 2012 at 07:13 PM 0
Share

Works, thanks.

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

2D Animation does not start 1 Answer

How to play an animation in reverse? 1 Answer

Playing an animation when press left mouse key - Using Orthello JavaScript 1 Answer

Two Animations With One Button Press 1 Answer

Spine animation: how to use a skeleton from a project to transfer to a new project in Spine? 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