I have inserted this script into the FPS controller and I am adjusting any numerical values to my games. I am currently working on the section to do with Crouch but when ever I try to activate this event it says that uncrouchFixRaycastOriginA has not been assigned. Does anyone know how I can solve this? The whole coding is:
using UnityEngine;
using System.Collections;
public class Crouchv3 : MonoBehaviour {
public float crouchHeightOffset = 0.9f;
private CharacterMotor charMotor;
private CharacterController charCont;
public Transform uncrouchFixRaycastOriginA;
public Transform uncrouchFixRaycastOriginB;
public Transform uncrouchFixRaycastOriginC;
public Transform uncrouchFixRaycastOriginD;
public float smoothTime = 0.3f;
private float targetY = 0;
private float velocityY = 0;
public static bool canSprint = true;
public static bool isSprinting = false;
public static bool crouch = false;
private bool canStandUp = true;
public static bool isWalking = false;
void Start ()
{
charMotor = GetComponent<CharacterMotor>();
charCont = GetComponent<CharacterController>();
}
void LateUpdate()
{
if (Input.GetButtonDown("Crouch") && canStandUp) {
crouch=true;
isWalking=false;
isSprinting=false;
targetY = -crouchHeightOffset;
charMotor.movement.maxForwardSpeed = 2.75f;
charMotor.movement.maxBackwardsSpeed = 2.75f;
charMotor.movement.maxSidewaysSpeed = 2.6f;
charCont.center = new Vector3(0, -crouchHeightOffset/2, 0);
charCont.height = 1.1f;
}
if (!Input.GetButton("Crouch") && canStandUp) {
crouch=false;
targetY = 0;
charMotor.movement.maxForwardSpeed = 193.77f;
charMotor.movement.maxBackwardsSpeed = 100f;
charMotor.movement.maxSidewaysSpeed = 100f;
charCont.center = Vector3.zero;
charCont.height = 2.0f;
if(Input.GetAxis("Vertical") != 0 || Input.GetAxis("Horizontal") != 0)
{
if(Input.GetButton("Sprint"))
{
if (canSprint)
{
if(Input.GetAxis("Vertical") > 0 && Input.GetAxis("Horizontal") == 0 && !crouch)
{
isWalking = false;
charMotor.movement.maxForwardSpeed = 300f;
isSprinting = true;
} else isSprinting = false;
}
}
else if(Input.GetButton("Walk"))
{
isSprinting = false;
isWalking = true;
charMotor.movement.maxForwardSpeed = 193.77f;
charMotor.movement.maxBackwardsSpeed = 100f;
charMotor.movement.maxSidewaysSpeed = 100f;
}
else if(!crouch)
{
isSprinting = false;
isWalking = false;
charMotor.movement.maxForwardSpeed = 5.5f;
charMotor.movement.maxBackwardsSpeed = 5.5f;
charMotor.movement.maxSidewaysSpeed = 5.35f;
}
}
}
if(Physics.Raycast(uncrouchFixRaycastOriginA.position, Vector3.up, crouchHeightOffset)||Physics.Raycast(uncrouchFixRaycastOriginB.position, Vector3.up, crouchHeightOffset)||Physics.Raycast(uncrouchFixRaycastOriginC.position, Vector3.up, crouchHeightOffset)||Physics.Raycast(uncrouchFixRaycastOriginD.position, Vector3.up, crouchHeightOffset))
canStandUp=false; else canStandUp=true;
float newY = Mathf.SmoothDamp(Camera.main.transform.localPosition.y, targetY, ref velocityY, smoothTime);
Camera.main.transform.localPosition = new Vector3(0, newY, 0);
charMotor.jumping.enabled = !crouch;
}
}