• 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 niconicon · May 09, 2017 at 05:22 AM · c#floattypeoperator

error CS0019: Operator `&' cannot be applied to operands of type `float' and `float'

Hi this code that´s ok but I want to set "running" when the player press left shift... In this original code of tutorial in their functions are walk and jump but miss run. I don´t know how to make this...

    [System.Serializable]
     public class MoveSettings{
         public float runVel = 30;
         public float forwardVel = 12;
         public float rotateVel = 100;
         public float jumpVel = 25;
         public float distToGrounded = 0.1f;
         public LayerMask ground;
     }
 
     [System.Serializable]
     public class PhysSettings{
         public float downAccel = 0.75f;
     }
 
     [System.Serializable]
     public class InputSettings{
         public float inputDelay = 0.1f;
         public string JUMP_AXIS = "Jump";
         public string TURN_AXIS     = "Horizontal";
         public string FORWARD_AXIS = "Vertical";
         public string RUN_AXIS = "Speed";
     }
 
     public MoveSettings moveSetting = new MoveSettings ();
     public PhysSettings physSetting = new PhysSettings ();
     public InputSettings inputSetting = new InputSettings ();
 
     Vector3 movement;                   // The vector to store the direction of the player's movement.
     Animator anim;                      // Reference to the animator component.
     Rigidbody rBody;          // Reference to the player's rigidbody.
 
 
     Vector3 velocity = Vector3.zero;
     Quaternion targetRotation;
     float jumpInput, turnInput, forwardInput, runInput;
 
 
     public bool alive = true;
 
     void onTriggerEnter(Collider other){
         if (other.gameObject.name == "eyes") {
             other.transform.parent.GetComponent<GuardaRealMovement6> ().checkSight();
         }
     }
 
     public Quaternion TargetRotation {
         get{ return targetRotation; }
     }
 
     bool Grounded(){
         return Physics.Raycast (transform.position, Vector3.down, moveSetting.distToGrounded, moveSetting.ground);
     }
 
     void Awake ()
     {
         
         anim = GetComponent <Animator> ();
     
     }
     void Start(){
         targetRotation = transform.rotation;
         if (GetComponent<Rigidbody> ())
             rBody = GetComponent<Rigidbody> ();
         else
             Debug.LogError ("The character needs a rigidbody.");
         
         forwardInput = turnInput = jumpInput = runInput = 0;
 
     }
 
     void GetInput(){
         forwardInput = Input.GetAxis (inputSetting.FORWARD_AXIS);
         jumpInput = Input.GetAxisRaw (inputSetting.JUMP_AXIS);
         turnInput = Input.GetAxis (inputSetting.TURN_AXIS);
         runInput = Input.GetAxisRaw (inputSetting.RUN_AXIS);
     }
     void Update(){
         GetInput ();
         Turn ();
 
     }
 
     void FixedUpdate ()
     {
         
         // Animate the player.
     
 
         Animating (forwardInput);
         RunFast ();
         Run ();
         Jump ();
         rBody.velocity = transform.TransformDirection (velocity);
 
     }
     void Animating (float forwardInput)
     {
         // Create a boolean that is true if either of the input axes is non-zero.
         bool walking = forwardInput != 0f;
 
         // Tell the animator whether or not the player is walking.
         anim.SetBool ("IsWalking", walking);
     }
 
     void Run (){
         if(Mathf.Abs(forwardInput)>inputSetting.inputDelay){
             //move
             //rBody.velocity = transform.forward*forwardInput*moveSetting.forwardVel;
             velocity.z = moveSetting.forwardVel*forwardInput;
         }
         else{
             //zero.velocity
             //rBody.velocity=Vector3.zero;
             velocity.z = 0;}
         }
     void RunFast (){
         if(Mathf.Abs(forwardInput & runInput)>inputSetting.inputDelay){
             //move
             //rBody.velocity = transform.forward*forwardInput*moveSetting.forwardVel;
             velocity.z = moveSetting.runVel*forwardInput;
         }
         else{
             //zero.velocity
             //rBody.velocity=Vector3.zero;
             velocity.z = 0;}
     }
 
 
     void Turn ()
     {
         if (Mathf.Abs (turnInput) > inputSetting.inputDelay) {
 
             targetRotation *= Quaternion.AngleAxis (moveSetting.rotateVel * turnInput * Time.deltaTime, Vector3.up);
         }
         transform.rotation = targetRotation;
     }
     void Jump(){
         if(jumpInput>0 && Grounded()){
             //jump
             velocity.y=moveSetting.jumpVel;
         }
         else if(jumpInput == 0 && Grounded()){
             //zero out our velocity
             velocity.y=0;
         }
         else{
             //decrease velocity.y
             velocity.y -=physSetting.downAccel;
         }
 
     }
 
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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Neural Network type conversion problem 1 Answer

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Operator || cannot be applied to types float and float? 1 Answer

float = int / int float value always 0 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges