Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Timers;
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- public const float defaultMS = 10f;
- static Timer timer1;
- public Camera camera;
- public float moveSpeed = 10f;
- public static float MS = 10f;
- public float jumpForce;
- public float raycastDistance;
- private static float time = 5f;
- private static bool speedBoostRanOut;
- public Rigidbody playerRigidBody;
- public Transform playerTransform;
- bool isCrouchPressed;
- bool isJumpPressed;
- bool isCrouching = false;
- bool isStanding = true;
- Vector3 tempScale;
- Vector3 curCamHeight;
- public Vector3 crouchCamHeight;
- void Start()
- {
- camera = Camera.main;
- curCamHeight = camera.transform.position;
- }
- void Update()
- {
- isCrouchPressed = Input.GetButtonDown("Crouch");
- isJumpPressed = Input.GetButtonDown("Jump");
- float zMovement = Input.GetAxis("Vertical") * moveSpeed;
- float xMovement = Input.GetAxis("Horizontal") * moveSpeed;
- zMovement *= Time.deltaTime;
- xMovement *= Time.deltaTime;
- playerTransform.Translate(0, 0, zMovement);
- playerTransform.Translate(xMovement, 0, 0);
- }
- void FixedUpdate()
- {
- moveSpeed = MS;
- if (isGrounded() && isJumpPressed)
- {
- playerRigidBody.AddForce(0, jumpForce, 0, ForceMode.Impulse);
- }
- if (isCrouchPressed)
- {
- if (isCrouching)
- {
- Stand();
- }
- else
- {
- Crouch();
- }
- }
- }
- public static void ActivateSpeedBoost(Collision collision)
- {
- // constant until death
- MS += 2;
- collision.collider.enabled = false;
- collision.collider.transform.position = new Vector3(1, -100, 1);
- }
- private void Stand()
- {
- MS *= 2;
- moveSpeed *= 2;
- jumpForce = (jumpForce - 3) * 2;
- tempScale = transform.localScale;
- tempScale.y *= 2f;
- transform.localScale = tempScale;
- camera.transform.position = new Vector3(camera.transform.position.x,
- camera.transform.position.y + 0.6f,
- camera.transform.position.z);
- isCrouching = false;
- isStanding = true;
- }
- private void Crouch()
- {
- MS /= 2;
- moveSpeed /= 2;
- jumpForce = (jumpForce / 2) + 3;
- tempScale = transform.localScale;
- tempScale.y /= 2f;
- transform.localScale = tempScale;
- camera.transform.position = new Vector3(camera.transform.position.x,
- camera.transform.position.y - 0.6f,
- camera.transform.position.z);
- transform.position = new Vector3(
- transform.position.x,
- transform.position.y - 0.6f,
- transform.position.z);
- isCrouching = true;
- isStanding = false;
- }
- bool isGrounded()
- {
- return Physics.Raycast(playerTransform.position,
- Vector3.down,
- raycastDistance);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement