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 /
avatar image
0
Question by FloppyFish · Aug 23, 2017 at 10:15 PM · animationanimatorprogramminganimator controllersupport

(2D, C#) Why can't I affect transition parameters!

I'm trying to switch between 3 different character sprites depending on if the player hold down A or D (Walking) or idle. I thought It'd be easy to do through the animator but for some reason I can't control the logic parameters through my C# script.

Through console output i can see the variable in the script changing but not the actual animator parameter.

Been trying to find a solution for over 5 hours now so I'm fairly desperate.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerControl : MonoBehaviour {
 
     Animator cAnimator;
 
     // Use this for initialization
     void Start () {
         cAnimator = GetComponent<Animator>();
     }
     
     // Update is called once per frame
     void Update () {
         int cDebugRight = cAnimator.GetInteger("ToRight");
         int cDebugLeft = cAnimator.GetInteger("ToLeft");
 
         if (Input.GetKey(KeyCode.D))
         {
             transform.Translate(Vector2.right * 4f * Time.deltaTime);
             cAnimator.SetInteger("ToRight", 1);
         }
         else if (Input.GetKey(KeyCode.A))
         {
             transform.Translate(Vector2.left * 4f * Time.deltaTime);
             cAnimator.SetInteger("ToLeft", 1);
         }
         else
         {
             cAnimator.SetInteger("ToRight", 0);
             cAnimator.SetInteger("ToLeft", 0);
         }
         Debug.Log("Animator Parameter To Right: " + cDebugRight);
         Debug.Log("Animator Parameter To left: " + cDebugLeft);
     }
 }
 

alt text

alt text

rightselect.png (69.8 kB)
toright.png (65.6 kB)
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 hexagonius · Aug 26, 2017 at 04:36 AM 0
Share

Be sure to check all 4 transitions, in and out.
You showed a back transition but mention a forward transition is not even working.

avatar image $$anonymous$$ · Aug 26, 2017 at 05:29 AM 0
Share

Your script looks fine except you should set the opposite direction to 0 when you hit the direction key (although your animation will only idle in one direction), make sure you set a transition from directly left to right and right to left and define ToRight and ToLeft in all 6 transitions where:

 Idle -> Left: ToLeft  = 1, ToRight = 0
 Idle -> Right : ToLeft  = 0, ToRight = 1
 Left -> Idle: ToLeft  = 0, ToRight = 0
 Right -> Idle: ToLeft  = 0, ToRight = 0
 Left -> Right: ToLeft  = 0, ToRight = 1
 Right -> Left: ToLeft  = 1, ToRight = 0

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

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

Multiple Cars not working 1 Answer

How to handle multiple animation variants 1 Answer

Display additional animation on top of other animations 0 Answers

Animator Override Controller changed at runtime doesn't always play the animations correctly 1 Answer

Attempting to change AnimatorController during Runtime 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