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 SoundMatch · May 29, 2017 at 07:37 PM · animationscripting problemscript.state-machineticks

Animator Boolean not Changing by script C#

Hello! I have a problem when trying to change a state within my character.

using System.Collections; using UnityEngine;

public class Player : MonoBehaviour {

 public Animator anim;
 public Rigidbody rbody;

 private bool isOnGround = true;

 private bool jump = false;
 private bool doubleJump = false;
 //Stores the slide time
 private bool slide = false;
     public float slideTimer = 0f
 //Sets the maximum amount of time to slide;
 public float maxSlideTime = 0.01f;
 private bool rest = false;

 private float inputH;
 private float inputV;

 
 // Use this for initialization
 void Start () {
     anim = GetComponent<Animator>();
     rbody = GetComponent<Rigidbody>();
     
 }

 // Update is called once per frame
 void Update () {
         PlayerInput();
 }




 void PlayerInput(){
     if(Input.GetKeyDown("1")){
         print ("1 is Pressed");
         anim.Play("WAIT03", -1, 0f);
     }
     if(Input.GetMouseButtonDown(1) && !slide){
         print ("isSliding anim bool set true");
         //anim.Play("SLIDE00", -1, 0f);
         anim.SetBool("isSliding", true);
         rbody.useGravity = true;
         slideTimer = 0f;
         slide = true;
         gameObject.GetComponent<BoxCollider>().enabled = false;
     }
     /*if(slide){
         //slideTimer is given a tick rate in seconds.
         slideTimer += Time.deltaTime;
         //If slide timer is over max slide time then the slide with exit state
         if(slideTimer > maxSlideTime){
             anim.SetBool("isSliding", false);
             slide = false;
             gameObject.GetComponent<BoxCollider>().enabled = true;
         }
     }*/ 
      //Physics in Fixed Update
 void FixedUpdate()
 {
     if(jump == true){
         jump = false;
         rbody.velocity = new Vector2(0, 0);
         rbody.AddForce(new Vector2(0, 80f), ForceMode.Impulse);
     }

     if(slide == true){
         slide = false;
         rbody.velocity = new Vector2(0, 0);
         rbody.AddForce(new Vector2(80f, 0f), ForceMode.Acceleration);
     }

     if(rest == true){
         transform.position = new Vector3(-50f, 0, 0);
     }
 }

}

I've isolated the problem to the code if you look in the area where I've disabled the code in second if statement in PlayerInput(){}. In my animator when I left click it sets the anim.SetBool("isSliding", true); to true. However I want to make it set to false when the "slideTimer" exceeds the "maxSlideTime". I think maybe I didn't set the "slideTimer" to tick every second.

When I enable the code the value does change, however it doesn't tick, it merely changes once at a value ranging from around 0.015 to 0.022. How do I get the slideTimer to tick every second correctly?

Much thanks in advance.

alt text

2017-05-27-12-09-51.png (319.4 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 ShadyProductions · May 29, 2017 at 07:47 PM

In your fixed update you have the following which conflicts with your update method:

 if(slide == true){
      slide = false;

You probably need to add some more validation to that like

 if (slide == true && slideTimer > maxSlideTime) {
      slide = false;
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 SoundMatch · Jun 05, 2017 at 11:43 AM 0
Share

How the hell did I not notice that! Thank you so much!

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

I need help with my animations and script 0 Answers

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

GameObject from macinim ? 0 Answers

Script over animation movement 1 Answer

First script plays animation but second script stops if from playing said animation 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