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