Hey Guys, my issue is the camera continues to rotate when it shouldn’t,
[RequireComponent (typeof(CharacterController))]
public class PlayerController : MonoBehaviour {
public float PlayerHealth = 100.0f;
public float movementSpeed = 10.0f;
public float mouseSensitivity = 3.0f;
public float verticalRotation = 0;
public float udRange = 60.0f;
public float verticalVelocity = 0;
public float jumpSpeed = 5.0f;
public bool paused = false;
CharacterController cc;
// Use this for initialization
void Start () {
Screen.lockCursor = true;
}
// Update is called once per frame
if (!paused == true){
Movement();
if (Input.GetKeyDown(KeyCode.P))
{
paused = true;
}
}else
{
Time.timeScale = 0.0f;
if (Input.GetKeyDown(KeyCode.P) && paused == true)
{
paused = false;
Time.timeScale = 1.0f;
}
}
void Movement() {
cc = GetComponent<CharacterController>();
if (Input.GetKeyDown(KeyCode.E))
{
PlayerHealth -= 10.0f;
}
//Mouse
//Rotation
float rotLR = Input.GetAxis("Mouse X") * mouseSensitivity;
verticalRotation -= Input.GetAxis("Mouse Y") * mouseSensitivity;
transform.Rotate(0 ,rotLR ,0);
verticalRotation = Mathf.Clamp(verticalRotation, -udRange, udRange);
Camera.main.transform.localRotation = Quaternion.Euler(verticalRotation, 0, 0);
//mouse end
if (cc.isGrounded)
{
if (Input.GetButtonDown("Jump")){
verticalVelocity = jumpSpeed;
movementSpeed = 3.0f;
}
else{
movementSpeed = 10.0f;
}
if (Input.GetKey(KeyCode.LeftShift))
{
movementSpeed = 15.0f;
}else{
movementSpeed = 10.0f;
}
}
//Movement
float forwardSpeed = Input.GetAxis("Vertical") * movementSpeed;
float sideSpeed = Input.GetAxis("Horizontal") * movementSpeed;
//Velcity
verticalVelocity += Physics.gravity.y * Time.deltaTime;
Vector3 speed = new Vector3(sideSpeed ,verticalVelocity, forwardSpeed);
speed = transform.rotation * speed;
cc.Move( speed * Time.deltaTime );
}
}
Now it still instantiates and object even when paused
public class FPS_shooting : PlayerController {
public GameObject bullet_Prefab;
//public GameObject debris_Prefab;
public float cooldown = 0.8f;
public float cooldownRemaining = 0;
public float bulletImpulse = 20f;
public float range = 100.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (!paused == true)
{
cooldownRemaining -= Time.deltaTime;
if (Input.GetButton("Fire1") && cooldownRemaining <= 0)
{
cooldownRemaining = cooldown;
Camera cam = Camera.main;
GameObject theBullet = (GameObject)Instantiate(bullet_Prefab, cam.transform.position + cam.transform.forward, cam.transform.rotation);
theBullet.rigidbody.AddForce(cam.transform.forward * bulletImpulse, ForceMode.Impulse);
}
if (Input.GetButtonDown("Fire2") && cooldownRemaining <= 0)
{
cooldownRemaining = cooldown;
Camera cam = Camera.main;
GameObject theBullet = (GameObject)Instantiate(bullet_Prefab, cam.transform.position + cam.transform.forward, cam.transform.rotation);
theBullet.rigidbody.AddForce(cam.transform.forward * bulletImpulse * 1.5f, ForceMode.Impulse);
}
}
}
}