Initial commit

This commit is contained in:
2022-09-04 11:34:51 +03:00
commit 2265202f59
219 changed files with 69345 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraBob : MonoBehaviour
{
public bool Enable = true;
[Range(0, 0.1f)] public float Amplitude = 0.015f;
[Range(0, 30)] public float Frequency = 10;
public float YStrength = 1;
public float XStrength = 0.5f;
public Transform Camera;
public Transform CameraHolder;
public float ToggleSpeed = 3;
Vector3 StartPos;
CharacterController controller;
private void Update()
{
if (Enable)
{
CheckMotion();
ResetPosition();
CameraHolder.LookAt(FocusTarget());
}
}
private void Awake()
{
controller = GetComponent<CharacterController>();
StartPos = Camera.localPosition;
}
void PlayMotion(Vector3 motion)
{
Camera.localPosition += motion;
}
void CheckMotion()
{
if (controller.GetComponent<PlayerMovement>().PlayerState != PlayerMovement.CurrentState.Walk) return;
if (!controller.isGrounded) return;
PlayMotion(FootStepMotion());
}
Vector3 FootStepMotion()
{
Vector3 pos = Vector3.zero;
pos.y += Mathf.Sin(Time.time * Frequency) * Amplitude;
pos.x += Mathf.Cos(Time.time * Frequency / 2) * Amplitude *2;
return pos;
}
void ResetPosition()
{
if (Camera.localPosition == StartPos) return;
Camera.localPosition = Vector3.Lerp(Camera.localPosition, StartPos, Time.deltaTime);
}
Vector3 FocusTarget()
{
Vector3 pos = new Vector3(transform.position.x, transform.position.y + CameraHolder.localPosition.y, transform.position.z);
pos += CameraHolder.forward * 15;
return pos;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 36b966fd5829bfc4d929a3860d57ae12
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,68 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class CameraMovement : MonoBehaviour
{
[Header("Main")]
public float MouseSens = 200f;
float xRot;
public GameObject PlayerBody;
public int MaxCameraAngle = 80;
bool pause = false;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
private void FixedUpdate()
{
float mouseX = Input.GetAxis("Mouse X") * MouseSens * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * MouseSens * Time.deltaTime;
xRot -= mouseY;
xRot = Mathf.Clamp(xRot, -MaxCameraAngle, MaxCameraAngle);
transform.localRotation = Quaternion.Euler(xRot, 0, 0);
PlayerBody.transform.Rotate(Vector3.up * mouseX);
}
private void Update()
{
if (Input.GetKeyUp(KeyCode.Escape))
{
if (!pause)
{
Cursor.lockState = CursorLockMode.Confined;
pause = true;
StartCoroutine("PauseGame");
}
else
{
Cursor.lockState = CursorLockMode.Locked;
pause = false;
StartCoroutine("UnPauseGame");
}
}
}
IEnumerator PauseGame()
{
SceneManager.LoadSceneAsync("pause", LoadSceneMode.Additive);
Time.timeScale = 0;
return null;
}
IEnumerator UnPauseGame()
{
SceneManager.UnloadSceneAsync("pause" );
Time.timeScale = 1;
return null;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0873a8b84bf4f9540b08db84d88253b8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,127 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerMovement : MonoBehaviour
{
CharacterController PlayerController;
public float PlayerWalkSpeed = 5;
public float PlayerRunSpeed = 7;
public float CrouchWalkSpeed = 2;
public GameObject PlayerCamera;
public GameObject CameraHolder;
Vector3 Velocity;
[HideInInspector] public CurrentState PlayerState;
public bool isCrouch;
public float CrouchHeight = 0.4f;
float StartCameraPos;
public float CrouchCameraHeight = 0.1f;
public int stickCount = 0;
public Text TextStickCount;
public enum CurrentState
{
Idle = 0,
Walk,
Run,
Crouch,
CrouchWalk
}
// Start is called before the first frame update
void Start()
{
PlayerController = GetComponent<CharacterController>();
StartCameraPos = PlayerCamera.transform.localPosition.y;
}
// Update is called once per frame
private void FixedUpdate()
{
float xAxies = Input.GetAxis("Horizontal");
float zAxies = Input.GetAxis("Vertical");
Vector3 move = transform.right * xAxies + transform.forward * zAxies;
if (isCrouch)
{
PlayerController.Move(move * CrouchWalkSpeed * Time.deltaTime);
}
else
{
PlayerController.Move(move * PlayerWalkSpeed * Time.deltaTime);
}
if(PlayerController.velocity.magnitude == 0)
{
if (!isCrouch)
{
PlayerState = CurrentState.Idle;
}
else
{
PlayerState = CurrentState.Crouch;
}
}
else
{
if (!isCrouch)
{
PlayerState = CurrentState.Walk;
}
else
{
PlayerState = CurrentState.CrouchWalk;
}
}
//Debug.Log(PlayerState);
if (!PlayerController.isGrounded)
{
Velocity = Physics.gravity + Physics.gravity;
PlayerController.Move(Physics.gravity * Time.deltaTime);
}
}
private void Update()
{
TextStickCount.text = stickCount.ToString();
if (Input.GetKeyDown(KeyCode.LeftShift))
{
if (isCrouch)
{
if (!Physics.Raycast(PlayerCamera.transform.position, Vector3.up, 1f))
{
PlayerCamera.transform.localPosition = new Vector3(0, StartCameraPos, 0);
PlayerController.height = 1.88f;
isCrouch = false;
PlayerState = CurrentState.Idle;
PlayerController.Move(Vector3.up * Time.deltaTime * 10);
//Debug.LogError("Now Not Crouch");
}
}
else
{
PlayerCamera.transform.localPosition = new Vector3(0, CrouchCameraHeight, 0);
PlayerController.height = CrouchHeight;
isCrouch = true;
PlayerState = CurrentState.Crouch;
//Debug.LogError("Now Crouch");
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d959fe4ab337f274fa25daf28567a008
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: