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 cherrytechAirhead · Mar 18, 2016 at 12:17 PM · c#animatorscripting beginnerintegerparameter

Parameter Integer Not Changing for Animator Transitions (C#)

Hello there, Unity community, I am Sparx. I am having some troubles with coding- our teacher is not all that... good, at teaching, but we have to complete a project. I am very new to this, and if you could explain why your answer works, or what I did wrong in addition to answering my question so that I can learn from this, I would greatly appreciate it. But if you can just answer it, I'll be really grateful anyway. I'm very new to this, but I'll attempt to give as much information as I can.

I am using C# script, and have been following a video tutorial (https://www.youtube.com/watch?v=ohxPWVfizkA this is the part I am on, you can watch the previous ones if you want, but skip the spikes one, I didn't use that) almost to the letter, with a bit of editing to fit the newer system as needed by the program. I am trying to make a platformer (more or less, in functionality), and my sprite character already walks and jumps just fine. My problem is that I have an idle animation, and a walking animation, and I need it to transition between them if the sprite is moving or not. To do this, I put both animations in the Animator, and added an integer parameter (named AnimationState). I then made transitions between the Idle animation and the Walking animation, so that if the parameter integer equals 0, the idle animation runs, and when it equals 1, the walking animation triggers. It works the way Wabble did it in the video, but I think I've encountered some kind of problem- even though I watch the window as I run the game, the integer does not change as I press A or D, and therefore (likely due to the Entry block, as I've inferred that's what it does?) the idle animation plays continuously. I'd like help in figuring out how to fix this, or what went wrong? First, here's my code (it's the playercontroller script, attached to the dragon sprite and it works just fine doing every other job assigned to it in said script):

using UnityEngine; using System.Collections;

public class PLAYERCONTROLLERYEAH : MonoBehaviour { //Movement Variables public float speedForce; public Vector2 jumpVector; public bool isGrounded;

 public Transform grounder;
 public float radiuss;
 public LayerMask ground;
 
 Animator anim;
 
 Rigidbody2D rb;

void Start () { rb = GetComponent(); anim = GetComponent(); }

void Update () { //Moving Left/Right if (Input.GetKey(KeyCode.D)) { rb.velocity = new Vector2(speedForce, rb.velocity.y); transform.localScale = new Vector3(1, 1, 1); //Why does this not work? The parameter integer doesn't change, but it should. anim.SetInteger("AnimationState", 1); } else if (Input.GetKey(KeyCode.A)) { rb.velocity = new Vector2(-speedForce, rb.velocity.y); transform.localScale = new Vector3(-1, 1, 1); anim.SetInteger("AnimationState", 1); } else

         rb.velocity = new Vector2(0, rb.velocity.y);
 anim.SetInteger("AnimationState", 0);
         
     isGrounded = Physics2D.OverlapCircle (grounder.transform.position,radiuss,ground);
         
     if(Input.GetKey(KeyCode.W) && isGrounded==true)
         rb.AddForce( jumpVector, ForceMode2D.Force);
 }
 
 void OnDrawGizmos()
 {
     Gizmos.color = Color.white;
     Gizmos.DrawWireSphere (grounder.transform.position, radiuss);
 }

}

(Um, I'm not sure why it's so weird... I'm sorry, I'm really new to this site.)

And here's some hopefully helpful screenshots. alt text

alt text

The top half of the code that got messed up in this question, and a screenshot of the animator and other windows.

If you could help me out, or at least help me figure out what's going on, I would be extremely grateful!

top-half-of-code.png (140.1 kB)
unity-screenshot.png (216.8 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

1 Reply

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

Answer by cherrytechAirhead · Mar 30, 2016 at 04:13 PM

Edit- The real answer was hidden in the brackets. I had to add brackets around the else if (isGrounded) command (the lines under it, that is) and the W key commands, to match those above it.

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

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Why when creating new animator controller for the character the character is not walking right ? 0 Answers

How to Control animator of child objects 1 Answer

Play Animation several times 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