Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Jontiways · Oct 19, 2014 at 02:40 PM · booleannot workingtrue

Walk / Run script not working.

Hey, I am currently having trouble making my walk/ run script work. The problem I am having is when I use a Boolean that asked whether or not the character can run, it doesn't walk at all, even if the boolean is set to true.

What exactly am I doing wrong? Here is the code below.

 var Speed        : float = 0;//Don't touch this
 var MaxSpeed     : float = 1;//This is the maximum speed that the object will achieve
 var Acceleration : float = 10;//How fast will object reach a maximum speed
 var Acceleration2 : float = 20;
 var Acceleration3 : float = 30;
 var Deceleration : float = 10;//How fast will object reach a speed of 0
 var grounded :boolean = false; //Check if the player can jump
 var notgrounded :boolean = false; //Check if the player can jump
 var jumpspeed : float = 15; //Check how high the player can jump
 var animator : Animator;
 var walk : boolean = false; 
 var Canwalk : boolean = true;
 var count : float = 10;
 var count2 : float =3;
 var count3 : float = 1;
 var particle1 : GameObject;
 var particle2 : GameObject;
 //var Rigid : Rigidbody;
 
  
 function Update () {
 
 
     if ((Input.GetKey ("right")) && (Speed < MaxSpeed)||(Canwalk == true)) {
      
     Speed = Speed - Acceleration * Time.deltaTime;
     animator.SetFloat("Speed", 0.5);
     this.walk = true;
     {
         if (Input.GetKey(KeyCode.A)){
         animator.SetFloat("Speed", 1.2);
         Speed = Speed - Acceleration2 * Time.deltaTime; 
         count-=Time.deltaTime;
             if(count < 0){
             
             Speed = Speed - Acceleration3 * Time.deltaTime;
             animator.SetFloat("Speed", 2.2);
             count2-=Time.deltaTime;
             particle1.SetActive (true);
             particle2.SetActive (true);
                 if(count2 <0){
                 count=10;
                 count2=3;
                 particle1.SetActive (false);
                 particle2.SetActive (false);
     }
     }
     }
     }
     }
     
     
     
      if ((Input.GetKey ("left")) && (Speed < MaxSpeed)&&(Canwalk == true)){
           
             Speed = Speed + Acceleration * Time.deltaTime;
             animator.SetFloat("Speed", 0.5);
             this.walk = true;
                 {
                 if (Input.GetKey(KeyCode.A)){
                 animator.SetFloat("Speed", 1.2);
                 Speed = Speed + Acceleration2 * Time.deltaTime; 
                 count-=Time.deltaTime;
                     if(count < 0){
                    
                     Speed = Speed + Acceleration3 * Time.deltaTime;
                     animator.SetFloat("Speed", 2.2);
                     count2-=Time.deltaTime;
                     particle1.SetActive (true);
                     particle2.SetActive (true);
                         if(count2 <0){
                         count=10;
                         count2=3;
                         particle1.SetActive (false);
                         particle2.SetActive (false);
                         }
                         }
                         }
                         }
                         }
                         
    
    
    
 
 {
     if(Speed > Deceleration * Time.deltaTime)
         Speed = Speed - Deceleration * Time.deltaTime;
     else if(Speed < -Deceleration * Time.deltaTime)
         Speed = Speed + Deceleration * Time.deltaTime;
     else
         Speed = 0;
         animator.SetFloat("Speed", 0);
         this.walk = false;
 }
 
 if ((Input.GetKeyDown ("space"))&&(grounded == true ))
 {
 animator.SetBool ("Jump" , true);
 rigidbody.velocity.y = jumpspeed;
 grounded = false;
 notgrounded = true;
 
 }
 
 
 {
  
 transform.position.x = transform.position.x + Speed * Time.deltaTime;
 
 }
 }
 
 function  OnCollisionEnter (collision : Collision)
 {
 
 if (collision.gameObject.tag == "Platform")
 {
 animator.SetBool ("Jump" , false);
 grounded = true;
 notgrounded = false;
 
 }
 {
 if (collision.gameObject.tag == "Death"){
 //play animation
 Speed = 0;
 transform.position = Vector3(200.15732, 0.5440826, -0.9341621);
 //play animation
 
 }
 }
 
 }
 function OnCollisionStay (hit : Collision) { 
      if(hit.gameObject.tag == "Plateform"){
          transform.parent = hit.transform ; 
      }else{
          transform.parent = null;
  }
 }
 
 

Canwalk is the boolean causing this problem, if it taken out everything functions fine.

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

2 People are following this question.

avatar image avatar image

Related Questions

Code isn't working properly. ( == code thing ) 1 Answer

Initialize boolean array as all true Unity JS 2 Answers

problem on switching gun (a var don't turn true) 0 Answers

Boolean values not behaving as expected. Please Help?! 0 Answers

Boolean problem!! 2 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