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 /
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.

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

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Neural Network type conversion problem 1 Answer

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

Error CS0023: The '!' operator cannot be applied to operand of type 'void' 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