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 greatjulius · Sep 17, 2015 at 02:34 PM · animation2dscriptingbasicsfloatbool

-Then- statement for scipts.

Hi,

in my script I want to have a statement that if a float is 1 and gets smaller in the next seconds something happens but I don't know how to write this. I would need something like a "then" statement. In my case I want to activate a animation per bool if the float "speed" is 1 and shrinks. If the speed is at its minimum 0 the boul turns false. It may sounds a bit confusing but I would describe what I want to do like this.

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

Answer by Fewpwew130 · Sep 17, 2015 at 03:51 PM

Hi, maybe something like this:

     public float variableone;
     public Animator anim;
     
     void Update(){
         if (variableone == 1f){
         anim.SetBool("Speed", (bool));
     }
    }

Don't know if the code is right, though.

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 greatjulius · Sep 17, 2015 at 04:33 PM 0
Share

I don't think it is exactly what I need. I will explain more detailed what I want to do without uploading my whole 100 lines script. If my Player has the speed of 1 (his full speed) he runs as normally but as he turns and his speed isn't anymore 1 he slides (by activating a bool). But as well he has a speed of 0 this bool is false. That's why I need a kind of "then". This is what I imagined it could be like:

 if ($$anonymous$$athf.Abs(Input.GetAxis("Horizontal")) = 1)
 {
     then
     {
         if ($$anonymous$$athf.Abs(Input.GetAxis("Horizontal")) > 1)
         {
             sliding = true;
         }
     }
 }
 if ($$anonymous$$athf.Abs(Input.GetAxis("Horizontal")) = 0)
 {
     sliding = false;
 }

avatar image Positive7 greatjulius · Sep 17, 2015 at 04:55 PM 0
Share
 bool sliding;
     bool canSlide;
 
     void Update () {
         if ($$anonymous$$athf.Abs (Input.GetAxis ("Horizontal")) == 1) {
             Debug.Log ("Do Something");
             canSlide = true;
 
         }
         if ($$anonymous$$athf.Abs (Input.GetAxis ("Horizontal")) < 0.9f && $$anonymous$$athf.Abs (Input.GetAxis ("Horizontal")) > 0.1f && canSlide) {
             sliding = true;
             Debug.Log (sliding);
         }
 
         if ($$anonymous$$athf.Abs (Input.GetAxis ("Horizontal")) == 0) {
             sliding = false;
             canSlide = false;
             Debug.Log (sliding);
         }
     }
avatar image greatjulius Positive7 · Sep 17, 2015 at 05:09 PM 0
Share

At first thanks for you reply. It is nearly what I want. The only difference is that the player first has to reach the speed of 1 and then if the speed drops the sliding gets true. I put this part of you script in my script but sliding gets also activated if the speed of 1 was never reached yet.

Show more comments
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.

Follow this Question

Answers Answers and Comments

37 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

Related Questions

Getting attack to go back to false? 0 Answers

2D Spine Animation not playing 0 Answers

Import animation from Adobe Animate(JSON) 1 Answer

Professional shortcuts/functions for Animators in the Unity 0 Answers

Create Idle/Walk/Run Blendtree 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