- Home /
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
Your answer
![](https://koobas.hobune.stream/wayback/20220613165427im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
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