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 corriedotdev · Mar 20, 2014 at 09:54 PM · c#animationmobiletouch

Simple animation not playing using animation.Play();

I have two of the following, one for the left and one for the right. This moves the players position. There is a problem with the animation not playing though. Ive used javascript for it in the past and assign

 var Animator : GameObject;

Which i dont think you do for c#?

Any help is appreciated, thanks.

 using System.Collections;
 
 public class right_Movement : MonoBehaviour {
     
     public Texture2D button1; // Inital texture for the button
     public Texture2D button2; // Once pressed texture
     public GameObject Player; // Declares the player from a gameobject 
     public int speed;
     public Animator anim;
 
     void Start () 
     {
         anim = gameObject.GetComponent<Animator>();
         guiTexture.texture = button1; // gui texture is made into button1
     }
     
 
     void Update () // If the screen is touched 
     {
         foreach (Touch touch in Input.touches)
         {
             if (guiTexture.HitTest(touch.position) && touch.phase != TouchPhase.Ended) // If the gui texture is touched then
             {
 
                 guiTexture.texture = button2; // The button changes to button2
 
                 anim.SetBool ("run_right", true);
             
                 Player.transform.Translate(Vector3.right * speed * Time.smoothDeltaTime); // Player slowly moves to the right
 
 
 
                 
                 
             }
             else if (guiTexture.HitTest(touch.position) && touch.phase == TouchPhase.Ended) // until the player stops touching the screen
             {
                 guiTexture.texture = button1; // gui texture reverts back to the original 
 
                 anim.SetBool ("run_right", true);
 
             }
         }
     }
 }

Comment
Add comment · Show 9
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 suribe · Mar 20, 2014 at 09:58 PM 0
Share

is that animation "left_run" added through code, or through the editor?

avatar image corriedotdev · Mar 20, 2014 at 10:02 PM 0
Share

Left run has not been added at all. All of them - bar the idle - are in the project window waiting advise. I dont know how to assign "left_run".

avatar image MousePods · Mar 20, 2014 at 10:17 PM 0
Share

Then add it =P

alt text

Add the "Animtion" component and put the clip in the Animation slot.

avatar image MousePods · Mar 21, 2014 at 02:48 AM 0
Share

Could you package up the script and animation and post it here? I can take a look at it. I don't think I can debug it with just the info you posted. $$anonymous$$aybe someone else can, but I need to see settings and such :{ I know what it feels like spending hours on a glitch. Its terrible =(

avatar image corriedotdev · Mar 21, 2014 at 02:12 PM 0
Share

The thing is you have to run unity remote to check if its working. I could send you the project, however i will remove art e.t.c as this has been a project for sometime now, then i upgrade to 4.3 for the new 2d section and this happens ahha i don't feel comfortable sharing the project to everyone though.

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by corriedotdev · Mar 22, 2014 at 01:46 PM

Turns out that the gameobject was assigned to the player but i called gameobject instead of player. Silly

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 KelvinWright · Mar 21, 2014 at 06:11 AM

Try Player.animation.Play("left_run");

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 corriedotdev · Mar 21, 2014 at 10:48 AM 0
Share

ive already tried this thanks.

avatar image
0

Answer by suribe · Mar 21, 2014 at 07:48 AM

In the Animation component, set the Animations value (collapsed in the picture you show) to 1. It will then show a slot for adding an animation, similar to the one called "Animation" which now says "None". Drag from your project resources the "left_run" animation to the slot, and try again.

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 corriedotdev · Mar 21, 2014 at 10:44 AM 0
Share

Thanks for helping me out, i have spent the past 10 $$anonymous$$utes looking at what you said and not sure what you mean. Did you want me to set the animations to legacy? I would appreciate any help man really, thanks!

avatar image suribe · Mar 21, 2014 at 10:57 AM 0
Share

Is there a console message complaining about legacy animations?

avatar image suribe · Mar 21, 2014 at 03:21 PM 0
Share

There are some rough parts in the whole Animator vs. Animation handling, and this "marked as Legacy" is really annoying, because there is actually no way to mark an animation as legacy. :) You have both an Animator and Animation component. If you are doing this from scratch, I suggest just leave the animator, read the tutorials on how to use it, and create different states for you animation, switching between them with a trigger. It's more work at first, but once you have it setup it will probably be easier to add new animations. And it is clearly the way Unity will be in the future, everything inside Animation Controllers.

avatar image corriedotdev · Mar 21, 2014 at 05:05 PM 0
Share

Setting it to legacy is in the animations debug windows with a value of 1 ins$$anonymous$$d of the default of 2? No? I understand what your saying.

So basically there is nothing obvious that is wrong with my script and set up so i have to look into the animator. Damn haha

avatar image corriedotdev · Mar 21, 2014 at 07:28 PM 0
Share

Ok so i have managed to get the animation to work on the pc with no problems. I made another question here which has both scripts. Basically there is something wrong with my android code for playing it and i dont know what it is. 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

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

Related Questions

Converted PC player controls to Mobile not working 2 Answers

Multiple Cars not working 1 Answer

Help with c# code - Multitouch 1 Answer

Turning touch to rotation 1 Answer

How to make GUI pop up when you touch other gui 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