• 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 /
  • Help Room /
avatar image
0
Question by Ejpj123 · May 08, 2016 at 12:25 AM · animationmovingstopworkingwont

Animation and Stop Moving Won't Work?

Hi, I'm making a 2D infinite runner, and I am having trouble with this script.

 using UnityEngine;
 using System.Collections;
 using System;
 
 namespace UnityStandardAssets._2D
 {
     public class PlatformerCharacter2D : MonoBehaviour
     {
         bool CanMove = true;
         bool MoveWait=false;
 
         void OnCollissionEnter2D(Collision col1){
             if (col1.gameObject.tag == "Enemy") {
                 GetComponent<Animation> ().Play ("RedGiantDeathToAll");
                 CanMove = false;
                 if (!MoveWait)
                     StartCoroutine (MoveToWait ());
             }
         }
 
         public IEnumerator MoveToWait(){
             MoveWait=true;
             yield return new WaitForSeconds(1.5f); //Change to Animation Duration
             MoveWait=false;
             CanMove=true;
         }
     }
 }

There are no errors. But it won't work. When I run the game, the animation won't play. I have 2D box colliders on all enemies and the player. I have a tag called "Enemy" and I put it on all the enemies. The tag for the enemy is the same. I have colliders on both gameObjects, and there are 2D Rigidbody's on both, too. There is no spelling errors. Turns out the death animation was named, "Die", not "RedGiantDeathToAll". It used to be named that.

Please help! I'd be grateful!!

Comment
Add comment · Show 1
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 Ejpj123 · May 09, 2016 at 04:10 AM 0
Share

Could Someone Please Help $$anonymous$$e? Urgent!

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by UsmanAbbasi · May 09, 2016 at 08:05 AM

  • Is this condition ever becoming true? "if (col1.gameObject.tag == "Enemy") " If this line is being executed and animation is not running then check the name of this animation "GetComponent ().Play ("RedGiantDeathToAll");".

  • Also check the spelling of tag. There is a difference between "Enemy" and "enemy".

  • If the condition is not becoming true then check if function "void OnCollissionEnter2D(Collision col1)" is being called or not. If not then collisions are not being detected. To detect collisions you need to have colliders on both Game Objects and "RigidBody2d" on at least one of them. Also check that "Trigger" property in Collider inspector is not checked.

Comment
Add comment · Show 7 · 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 Ejpj123 · May 09, 2016 at 09:55 PM 0
Share

I have colliders on both gameObjects, and there are 2DRigidbody's on both, too. There is no spelling errors. Turns out the death animation was named, "Die", not "RedGiantDeathToAll". It used to be named that. Here are some errors I am having:

alt text

Ignore the first default clip. It has nothing to do with my problem. The second default clip is for the player. No animation attached for the player in the game.

screen-shot-2016-05-09-at-44643-pm.png (26.9 kB)
avatar image UsmanAbbasi · May 10, 2016 at 06:00 AM 0
Share

Okay this is what you should do: https://www.youtube.com/watch?v=yH9_SV58SuA

Follow instructions in the video. There might be a slight difference in settings i.e. in video, "animation type" property is changed, in your unity version maybe there will be a checkbox named "Legacy", just check that checkbox and your animation will work.

avatar image Ejpj123 UsmanAbbasi · May 11, 2016 at 12:31 AM 0
Share

It is no longer and infinite runner (the game I am making) I am holding down the right arrow to make the player move. The animation won't play, for some reason. Is it because I am holding it is no longer and infinite runner type game? I have 3 more errors:

alt text

and this:

alt text

screen-shot-2016-05-10-at-73647-pm.png (29.8 kB)
avatar image UsmanAbbasi Ejpj123 · May 11, 2016 at 05:54 AM 0
Share

This is the same warning you were getting before. $$anonymous$$ark the animations mentioned in warning as "Legacy" as shown in the video link.

Show more comments

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

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

Related Questions

How to set the speed to 0 1 Answer

Animation Won't Loop (But others will) 0 Answers

How do I get my character to stop moving while he is attacking? 0 Answers

script to move the character to the left, right, jump and slide .... with your finger sliding on the phone screen (swipe) 0 Answers

Cant get my walk animations to work in Unity 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