Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by windmarble · Aug 12, 2016 at 03:17 PM · animationscripting problemanimatoranimator controller

Animator is not firing transitions.

I have a PlayerMovement script attached to a game object and am trying to get the animator to fire the correct animation. However I can't seem to get it to work at all. On Awake I get the Animator component. and in the Start function I start off by setting the property HasFlashlight which should notify the animator about what set of animations to use. Though I thought I had done everything correctly. But apparently not. Any help?

 using UnityEngine;
 using System.Collections;
 
 
 public class PlayerMovementController : MonoBehaviour {
 
     private Rigidbody2D rigidBody;
     private Animator anim;
 
     public float moveSpeed; //The speed at which the player will move at
 
     /// <summary>
     /// Equipment
     /// </summary>
     /// 
 
     private bool hasFlashlight;
 
     public bool HasFlashlight {
         get {return hasFlashlight;}
         set { hasFlashlight = value;
             if(hasRifle){
                 anim.SetBool ("hasFlashlight", true);
             } else {
                 anim.SetBool ("hasFlashlight", false);
             }
         }
     }
         
     /// <summary>
     /// Actions
     /// </summary>
     private bool isWalking;
     public bool IsWalking {
         get {return isWalking;}
         set { isWalking = value;
             if(isWalking){
                 anim.SetBool ("isWalking", true);
             } else {
                 anim.SetBool ("isWalking", false);
             }
         }
     }
 
     private bool isMeleeing;
     public bool IsMeleeing {
         get {return isMeleeing;}
         set { isMeleeing = value;
             Debug.Log (@"Melee");
             if(isMeleeing){
                 Debug.Log (@"Melee - TRUE");
                 anim.SetBool ("isMeleeing", true);
             } else {
                 Debug.Log (@"Melee - FALSE");
                 anim.SetBool ("isMeleeing", false);
             }
 
         }
     }
         
     void Awake () {
         rigidBody = gameObject.GetComponent<Rigidbody2D> ();
         anim = gameObject.GetComponent<Animator> ();
     }
 
     void Start() {
         HasFlashlight = true;
     }
 
     void FixedUpdate () {
         move ();
         movementCheck ();
         melee ();
     }
 
 
     private void melee() {
         if(!IsMeleeing){
             if(Input.GetKeyDown(KeyCode.M)){
                 IsMeleeing = true;
             } else {
                 IsMeleeing = false;
             }
         }
             
     }
 
     private void move() {
         Vector2 rigV = rigidBody.velocity;
 
         //Player Movement
         if(Input.GetKeyDown(KeyCode.W)){
             rigV.y = moveSpeed;
         }
 
         if(Input.GetKeyDown(KeyCode.A)){
             rigV.x = -moveSpeed;
         }
 
         if(Input.GetKeyDown(KeyCode.S)){
             rigV.y = -moveSpeed;
         }
 
         if(Input.GetKeyDown(KeyCode.D)){
             rigV.x = moveSpeed;
         }
 
         rigidBody.velocity = rigV;
 
         //Player Rotation
         Vector3 objectPos = new Vector3(0,0,0);
         Vector3 dir = new Vector3(0,0,0);
 
         objectPos = Camera.main.WorldToScreenPoint(transform.position);
         dir = Input.mousePosition - objectPos; 
 
         transform.rotation = Quaternion.Euler(new Vector3(0,0,Mathf.Atan2(dir.y,dir.x) * Mathf.Rad2Deg ));
     
     }
 
     private void movementCheck(){
         if(!Input.GetKey (KeyCode.D) && !Input.GetKey (KeyCode.A) && !Input.GetKey (KeyCode.S) && !Input.GetKey (KeyCode.W)){
             IsWalking = false; 
             rigidBody.velocity = new Vector2(0,0);
         } else {
             IsWalking = true ; 
         }
     }
 }
 





Here is my Animator

alt text

And here is my player alt text

capturfiles-aug-12-2016-110329.png (155.9 kB)
capturfiles-aug-12-2016-111125.png (64.0 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

130 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 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

NEED HELP ANIMATING PLAYER MOVEMENT 0 Answers

Using same animator for multiple game objects 0 Answers

Confused about animations 1 Answer

Animator Check the end of an animation 1 Answer

Why default animation state rewrites scale of an object? 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