- Home /
 
 
               Question by 
               Snownebula · Jul 27, 2015 at 04:35 PM · 
                unity 5movementcharacter controllercharacter movementanimate  
              
 
              Character controler Script
I am trying to make it so I can have a Run when the user presses down the LeftShift. I get this error: Assets/UMA/Example/Scripts/Locomotion.cs(29,41): error CS0019: Operator &&' cannot be applied to operands of type float' and bool. And I also get this error too: Assets/UMA/Example/Scripts/Locomotion.cs(30,41): error CS0019: Operator &&' cannot be applied to operands of type float' and bool'. I am not sure how to fix it at this point, any help would be great. This is the script: using UnityEngine; using System.Collections;
 public class Locomotion : MonoBehaviour {
 
     protected Animator animator;
     public float DirectionDampTime = .25f;
 
     void Start () 
     {
         animator = GetComponent<Animator>();
     
         if (animator == null) return;
         if(animator.layerCount >= 2)
             animator.SetLayerWeight(1, 1);
     }
         
     void Update () 
     {
         if (animator)
         {        
               float h = Input.GetAxis("Horizontal");
             float v = Input.GetAxis("Vertical");
             
             animator.SetFloat("Walk", h*h+v*v);
             animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);    
         } else if (animator)
         {
             float h = Input.GetAxis ("Horizontal") && Input.GetKeyDown (KeyCode.LeftShift);
             float v = Input.GetAxis ("Vertical") && Input.GetKeyDown (KeyCode.LeftShift);
 
             animator.SetFloat("Run", h*h+v*v);
             animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);
         }
         else
         {
             animator = GetComponent<Animator>();
         }
     }
 
     
     void OnCollisionEnter(Collision collision)
     {
         Debug.Log(collision.collider.name + ":" + name);
     }
 
 }
 
              
               Comment
              
 
               
              Answer by Positive7 · Jul 27, 2015 at 04:46 PM
 void Update () 
 {
     if (animator)
     {        
         float h = Input.GetAxis("Horizontal");
         float v = Input.GetAxis("Vertical");
         
         animator.SetFloat("Walk", h*h+v*v);
         animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);    
     } else if (animator && Input.GetKeyDown (KeyCode.LeftShift))
     {
             float h = Input.GetAxis ("Horizontal");
             float v = Input.GetAxis ("Vertical");
         
             animator.SetFloat("Run", h*h+v*v);
             animator.SetFloat("Direction", h, DirectionDampTime, Time.deltaTime);
     }
     else
     {
         animator = GetComponent<Animator>();
     }
 }
 
              Your answer