Question by
AlphaTest · Apr 20, 2016 at 04:48 AM ·
error message
It says I have to go to the input manager and input the following code and I don't know how to do that./ Help Please? Anybody/
using UnityEngine; using System.Collections;
[RequireComponent(typeof(CharacterController))] public class PlayerMovement : MonoBehaviour { public bool canControl = true;
public float runSpeed = 5.0f;
public float sprintSpeed = 8.0f;
public AnimationCurve slopeSpeedMultiplier = new AnimationCurve(new Keyframe(-90, 1.5f), new Keyframe(0, 1), new Keyframe(90, 0));
public float crouchSpeedModifier = 0.55f;
public float normalHeight = 1.75f;
public float crouchHeight = 1.0f;
public float gravity = 9.81f;
public float maxFallSpeed = 100.0f;
public float jumpHeight = 2.0f;
public LayerMask crouchDetect;
public float pushPower = 1.6f;
[HideInInspector] public CollisionFlags collisionFlags;
[HideInInspector] public bool grounded;
[HideInInspector] public bool sprinting;
[HideInInspector] public bool crouching;
[HideInInspector] public bool inAir;
[HideInInspector] public bool floating;
[HideInInspector] public float impactVelocity;
[HideInInspector] public CharacterController controller;
private bool dontStand = false;
private RaycastHit ds;
private float moveSpeedAim;
private float curSpeed;
private Vector3 moveDirection;
void Start() {
controller = GetComponent<CharacterController>();
moveSpeedAim = 1;
}
void LateUpdate() {
if(!grounded) {
impactVelocity = -controller.velocity.y;
floating = true;
}
}
void Update() {
grounded = controller.isGrounded;
if(grounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal") * moveSpeedAim, -1, Input.GetAxis("Vertical") * moveSpeedAim);
if(moveDirection != Vector3.zero) {
float directionLength = moveDirection.magnitude;
moveDirection /= directionLength;
directionLength = Mathf.Min(1, directionLength);
directionLength = Mathf.Pow(directionLength, 2);
moveDirection *= directionLength;
}
moveDirection = transform.TransformDirection(moveDirection);
if(Input.GetButton("Run") && Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") > 0 && !crouching && controller.velocity.magnitude > 0.5f) {
moveDirection *= sprintSpeed;
sprinting = true;
}
else if(crouching && !sprinting) {
moveDirection *= runSpeed * crouchSpeedModifier;
}
else {
moveDirection *= runSpeed;
sprinting = false;
}
if(Input.GetButton("Jump")) {
moveDirection.y = jumpHeight;
}
if(Physics.Raycast(transform.position, transform.up, out ds, (controller.height * 0.5f) + 0.1f, crouchDetect.value)) {
dontStand = true;
}
else {
dontStand = false;
}
if(!sprinting) {
if(Input.GetButton("Crouch")) {
controller.height = Mathf.Lerp(controller.height, crouchHeight, Time.deltaTime * 6);
controller.center = new Vector3(0, Mathf.Lerp(controller.center.y, -((normalHeight - crouchHeight) / 2), Time.deltaTime * 6), 0);
GameObject.Find("Head").SendMessage("CrouchMoveY", -(normalHeight - crouchHeight));
crouching = true;
}
if(!Input.GetButton("Crouch") && !dontStand){
controller.height = Mathf.Lerp(controller.height, normalHeight, Time.deltaTime * 6);
controller.center = new Vector3(0, Mathf.Lerp(controller.center.y, 0, Time.deltaTime * 6), 0);
GameObject.Find("Head").SendMessage("CrouchMoveY", 0.0f);
crouching = false;
}
}
}
else {
inAir = true;
}
if(moveDirection.y > -maxFallSpeed) {
moveDirection.y -= Time.deltaTime * gravity;
}
controller.Move(moveDirection * Time.deltaTime);
}
void OnControllerColliderHit (ControllerColliderHit hit) {
}
public void SlowWhenAim(float spd) {
moveSpeedAim = spd;
}
}
Comment
Your answer
Follow this Question
Related Questions
Error CS0535? 0 Answers
Roll a Ball script error?! 2 Answers
NullReferenceException: Object reference not set to an instance of an object 1 Answer
Scene Won't Load 1 Answer
Socket: bind failed, error 3 Answers