Upload Game

This commit is contained in:
Michał Gdula 2023-03-14 14:43:42 +00:00
parent b3f494d5c2
commit 18b63ffa9b
150 changed files with 85782 additions and 0 deletions

View file

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraMove : MonoBehaviour
{
public Transform cameraPosition;
private void FixedUpdate()
{
transform.position = cameraPosition.position;
}
}

View file

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 B

View file

@ -0,0 +1,124 @@
fileFormatVersion: 2
guid: 14a6756fc65bff3409a9d9a1f0a953d4
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 12
mipmaps:
mipMapMode: 0
enableMipMap: 1
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
flipGreenChannel: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
vTOnly: 0
ignoreMasterTextureLimit: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: 1
aniso: 1
mipBias: 0
wrapU: 0
wrapV: 0
wrapW: 0
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 0
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
flipbookRows: 1
flipbookColumns: 1
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
ignorePngGamma: 0
applyGammaDecoding: 0
swizzle: 50462976
cookieLightType: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Standalone
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
- serializedVersion: 3
buildTarget: Server
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
nameFileIdTable: {}
spritePackingTag:
pSDRemoveMatte: 0
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,46 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCam : MonoBehaviour
{
public float sensX;
public float sensY;
public Transform orientation;
float xRotation;
float yRotation;
float mouseX;
float mouseY;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
mouseX = Input.GetAxisRaw("Mouse X") * Time.deltaTime * sensX;
mouseY = Input.GetAxisRaw("Mouse Y") * Time.deltaTime * sensY;
//}
//private void FixedUpdate()
//{
yRotation += mouseX;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
}

View file

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

View file

@ -0,0 +1,294 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour
{
[Header("Movement")]
private float moveSpeed;
public float walkSpeed;
public float sprintSpeed;
public float slideSpeed;
PlayerStamina playerStamina;
private float desiredMoveSpeed;
private float lastDesiredMoveSpeed;
public float speedIncreaseMultiplier;
public float slopeIncreaseMultiplier;
public float groundDrag;
public float jumpForce;
public float jumpCooldown;
public float airMultiplier;
bool readyToJump = true;
public float jumpStaminaCost = 10;
[Header("Crouching")]
public float crouchSpeed;
public float crouchYScale;
private float startYScale;
[Header("Keybinds")]
public KeyCode jumpKey = KeyCode.Space;
public KeyCode sprintKey = KeyCode.LeftShift;
public KeyCode crouchKey = KeyCode.LeftControl;
[Header("Ground Check")]
public float playerHeight;
public LayerMask whatIsGround;
public bool grounded;
[Header("Slope Handling")]
public float maxSlopeAngle;
private RaycastHit slopeHit;
private bool exitingSlope;
public Transform orientation;
float horizontalInput;
float verticalInput;
Vector3 moveDirection;
Rigidbody rb;
public MovementState state;
public bool cansprint = true;
public enum MovementState
{
walking,
sprinting,
crouching,
sliding,
air,
}
public bool sliding;
private void Start()
{
playerStamina = GetComponent<PlayerStamina>();
rb = GetComponent<Rigidbody>();
rb.freezeRotation = true;
readyToJump = true;
startYScale = transform.localScale.y;
}
private void Update()
{
grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.1f, whatIsGround);
MyInput();
SpeedControl();
StateHandler();
if (grounded)
rb.drag = groundDrag;
else
rb.drag = 0;
}
private void StateHandler()
{
if(sliding)
{
state = MovementState.sliding;
if (OnSlope() && rb.velocity.y < 0.1f)
desiredMoveSpeed = slideSpeed;
else
desiredMoveSpeed = sprintSpeed;
}
else if (Input.GetKey(crouchKey))
{
state = MovementState.crouching;
desiredMoveSpeed = crouchSpeed;
}
else if (grounded && cansprint && Input.GetKey(sprintKey))
{
state = MovementState.sprinting;
desiredMoveSpeed = sprintSpeed;
playerStamina.DecreaseStamina();
}
else if (grounded)
{
state = MovementState.walking;
desiredMoveSpeed = walkSpeed;
}
else
{
state = MovementState.air;
}
if(Mathf.Abs(desiredMoveSpeed - lastDesiredMoveSpeed) > 4f && moveSpeed !=0)
{
StopAllCoroutines();
StartCoroutine(SmoothlyLerpMoveSpeed());
}
else
{
moveSpeed = desiredMoveSpeed;
}
lastDesiredMoveSpeed = desiredMoveSpeed;
}
private IEnumerator SmoothlyLerpMoveSpeed()
{
float time = 0;
float difference = Mathf.Abs(desiredMoveSpeed - moveSpeed);
float startValue = moveSpeed;
while (time < difference)
{
moveSpeed = Mathf.Lerp(startValue, desiredMoveSpeed, time / difference);
if (OnSlope())
{
float slopeAngle = Vector3.Angle(Vector3.up, slopeHit.normal);
float slopeAngleIncrease = 1 + (slopeAngle / 90f);
time += Time.deltaTime * speedIncreaseMultiplier * slopeIncreaseMultiplier * slopeAngleIncrease;
}
else
time += Time.deltaTime * speedIncreaseMultiplier;
yield return null;
}
moveSpeed = desiredMoveSpeed;
}
private void FixedUpdate()
{
MovePlayer();
}
private void MyInput()
{
horizontalInput = Input.GetAxisRaw("Horizontal");
verticalInput = Input.GetAxisRaw("Vertical");
if(Input.GetKey(jumpKey) && readyToJump && grounded && playerStamina.DecreaseByChunk(jumpStaminaCost))
{
readyToJump = false;
Jump();
Invoke(nameof(ResetJump), jumpCooldown);
}
if (Input.GetKeyDown(crouchKey))
{
transform.localScale = new Vector3(transform.localScale.x, crouchYScale, transform.localScale.z);
rb.AddForce(Vector3.down * 5f, ForceMode.Impulse);
}
if(Input.GetKeyUp(crouchKey))
{
transform.localScale = new Vector3(transform.localScale.x, startYScale, transform.localScale.z);
}
}
private void MovePlayer()
{
moveDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;
if (OnSlope() && !exitingSlope)
{
rb.AddForce(GetSlopeMoveDirection(moveDirection) * moveSpeed * 20f, ForceMode.Force);
}
if(grounded)
rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);
else if(!grounded)
rb.AddForce(moveDirection.normalized * moveSpeed * 10f * airMultiplier, ForceMode.Force);
// if (rb.velocity.y > 0)
//rb.AddForce(Vector3.down * 80f, ForceMode.Force);
}
private void SpeedControl()
{
if (OnSlope() && !exitingSlope)
{
if (rb.velocity.magnitude > moveSpeed)
rb.velocity = rb.velocity.normalized * moveSpeed;
}
else
{
Vector3 flatVel = new Vector3(rb.velocity.x, 0f, rb.velocity.z);
if(flatVel.magnitude > moveSpeed)
{
Vector3 limitedVel = flatVel.normalized * moveSpeed;
rb.velocity = new Vector3(limitedVel.x, rb.velocity.y, limitedVel.z);
}
}
//text_speed.SetText("Speed: " + flatVel.magnitude);
}
private void Jump()
{
exitingSlope = true;
rb.velocity = new Vector3(rb.velocity.x, 0f, rb.velocity.z);
rb.AddForce(transform.up * jumpForce, ForceMode.Impulse);
}
private void ResetJump()
{
readyToJump = true;
exitingSlope = false;
}
public bool OnSlope()
{
if(Physics.Raycast(transform.position, Vector3.down, out slopeHit, playerHeight * 0.5f + 0.3f))
{
float angle = Vector3.Angle(Vector3.up, slopeHit.normal);
return angle < maxSlopeAngle && angle != 0;
}
return false;
}
public Vector3 GetSlopeMoveDirection(Vector3 directon)
{
return Vector3.ProjectOnPlane(directon, slopeHit.normal).normalized;
}
}

View file

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

View file

@ -0,0 +1,66 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerStamina : MonoBehaviour
{
private PlayerMovement pm;
public float stamina;
float maxStamina;
public Slider staminaBar;
public float dValue;
bool decreased = false;
void Start()
{
pm = GetComponent<PlayerMovement>();
maxStamina = stamina;
staminaBar.maxValue = maxStamina;
}
void Update()
{
if (stamina != maxStamina && !decreased)
IncreaseStamina();
decreased = false;
staminaBar.value = stamina;
}
public void DecreaseStamina()
{
if (stamina != 0)
stamina -= dValue * Time.deltaTime;
if(stamina <= 0)
{
pm.cansprint = false;
}
decreased = true;
}
public void IncreaseStamina()
{
stamina += dValue * Time.deltaTime;
if(stamina > maxStamina)
{
stamina = maxStamina;
}
if(stamina > maxStamina / 2)
{
pm.cansprint = true;
}
}
public bool DecreaseByChunk(float amount)
{
if(stamina > amount)
{
stamina -= amount;
return true;
}
return false;
}
}

View file

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

108
Assets/Movement/Sliding.cs Normal file
View file

@ -0,0 +1,108 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sliding : MonoBehaviour
{
[Header("References")]
public Transform orientation;
public Transform playerObj;
private Rigidbody rb;
private PlayerMovement pm;
PlayerStamina playerStamina;
[Header("Sliding")]
public float maxSlideTime;
public float slideForce;
private float slideTimer;
public float slideYScale;
private float startYScale;
[Header("Input")]
public KeyCode slideKey = KeyCode.LeftControl;
private float horizontalInput;
private float verticalInput;
public float slideStaminaCost = 20;
private void Start()
{
rb = GetComponent<Rigidbody>();
pm = GetComponent<PlayerMovement>();
playerStamina = GetComponent<PlayerStamina>();
startYScale = playerObj.localScale.y;
}
private void Update()
{
horizontalInput = Input.GetAxisRaw("Horizontal");
verticalInput = Input.GetAxisRaw("Vertical");
if (Input.GetKeyDown(slideKey) && (horizontalInput != 0 || verticalInput != 0))
StartSlide();
if (Input.GetKeyUp(slideKey) && pm.sliding)
StopSlide();
}
private void FixedUpdate()
{
if (pm.sliding)
SlidingMovement();
}
private void StartSlide()
{
if (!playerStamina.DecreaseByChunk(slideStaminaCost))
{
return;
}
pm.sliding = true;
playerObj.localScale = new Vector3(playerObj.localScale.x, slideYScale, playerObj.localScale.z);
rb.AddForce(Vector3.down * 5f, ForceMode.Impulse);
slideTimer = maxSlideTime;
}
private void SlidingMovement()
{
playerStamina.DecreaseStamina();
Vector3 inputDirection = orientation.forward * verticalInput + orientation.right * horizontalInput;
if(!pm.OnSlope() || rb.velocity.y > -0.1f)
{
rb.AddForce(inputDirection.normalized * slideForce, ForceMode.Force);
slideTimer -= Time.deltaTime;
}
else
{
rb.AddForce(pm.GetSlopeMoveDirection(inputDirection) * slideForce, ForceMode.Force);
}
if (slideTimer <= 0)
StopSlide();
}
private void StopSlide()
{
pm.sliding = false;
playerObj.localScale = new Vector3(playerObj.localScale.x, startYScale, playerObj.localScale.z);
}
}

View file

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