nahraná dosavadní verze hry
This commit is contained in:
19
3D blobici/Assets/Scripts/Player/CameraFollow.cs
Normal file
19
3D blobici/Assets/Scripts/Player/CameraFollow.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraFollow : MonoBehaviour
|
||||
{
|
||||
public Transform target; // The player's transform to follow
|
||||
public Vector3 offset = new Vector3(0f, 2f, -5f); // Offset from the target
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
// Update the camera's position to follow the target with an offset
|
||||
transform.position = target.position + offset;
|
||||
|
||||
// Make the camera look at the target
|
||||
transform.LookAt(target);
|
||||
}
|
||||
}
|
||||
11
3D blobici/Assets/Scripts/Player/CameraFollow.cs.meta
Normal file
11
3D blobici/Assets/Scripts/Player/CameraFollow.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29b10d799791ba548b694b2f7f25701b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
79
3D blobici/Assets/Scripts/Player/CameraManager.cs
Normal file
79
3D blobici/Assets/Scripts/Player/CameraManager.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraManager : MonoBehaviour
|
||||
{
|
||||
[Header("Target Settings")]
|
||||
public Transform target;
|
||||
|
||||
[Header("Position Settings")]
|
||||
public Vector3 offset = new Vector3(0f, 10f, -5f);
|
||||
public float followSpeed = 10f;
|
||||
|
||||
[Header("Zoom Settings")]
|
||||
public float zoomSpeed = 5f;
|
||||
public float minZoomHeight = 5f;
|
||||
public float maxZoomHeight = 15f;
|
||||
public float zoomZRatio = 0.5f; // How much Z changes relative to Y when zooming
|
||||
|
||||
// Current zoom level (0 = min zoom, 1 = max zoom)
|
||||
private float zoomLevel = 0.5f;
|
||||
|
||||
// Fixed camera rotation
|
||||
public Vector3 cameraRotation = new Vector3(45f, 0f, 0f);
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
Debug.LogWarning("No target assigned to CameraManager!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Set initial rotation
|
||||
transform.eulerAngles = cameraRotation;
|
||||
|
||||
// Position the camera immediately at start
|
||||
UpdateCameraPosition(false);
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
if (target == null)
|
||||
return;
|
||||
|
||||
// Handle zoom input
|
||||
float scrollInput = Input.GetAxis("Mouse ScrollWheel");
|
||||
if (scrollInput != 0)
|
||||
{
|
||||
// Update zoom level
|
||||
zoomLevel = Mathf.Clamp01(zoomLevel - scrollInput * zoomSpeed * Time.deltaTime);
|
||||
}
|
||||
|
||||
// Update camera position with smoothing
|
||||
UpdateCameraPosition(true);
|
||||
|
||||
// Ensure the camera rotation stays fixed
|
||||
transform.eulerAngles = cameraRotation;
|
||||
}
|
||||
|
||||
void UpdateCameraPosition(bool smooth)
|
||||
{
|
||||
// Calculate height and Z offset based on zoom level
|
||||
float height = Mathf.Lerp(minZoomHeight, maxZoomHeight, zoomLevel);
|
||||
float zOffset = -Mathf.Lerp(minZoomHeight * zoomZRatio, maxZoomHeight * zoomZRatio, zoomLevel);
|
||||
|
||||
// Create the target position
|
||||
Vector3 targetPosition = target.position + new Vector3(0, height, zOffset);
|
||||
|
||||
if (smooth)
|
||||
{
|
||||
// Smoothly move towards the target position
|
||||
transform.position = Vector3.Lerp(transform.position, targetPosition, followSpeed * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Instantly set position
|
||||
transform.position = targetPosition;
|
||||
}
|
||||
}
|
||||
}
|
||||
2
3D blobici/Assets/Scripts/Player/CameraManager.cs.meta
Normal file
2
3D blobici/Assets/Scripts/Player/CameraManager.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7d89920cdf28dc4b87af26ee136cf12
|
||||
27
3D blobici/Assets/Scripts/Player/CameraZoom.cs
Normal file
27
3D blobici/Assets/Scripts/Player/CameraZoom.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraZoom : MonoBehaviour
|
||||
{
|
||||
public float zoomSpeed = 10f; // Speed of zooming
|
||||
public float minZoom = 5f; // Minimum zoom distance
|
||||
public float maxZoom = 20f; // Maximum zoom distance
|
||||
|
||||
private Camera cam;
|
||||
|
||||
void Start()
|
||||
{
|
||||
cam = GetComponent<Camera>(); // Get the Camera component attached to the GameObject
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
// Get the scroll wheel input
|
||||
float scrollInput = Input.GetAxis("Mouse ScrollWheel");
|
||||
|
||||
// Calculate the new field of view (FOV)
|
||||
float newFOV = cam.fieldOfView - scrollInput * zoomSpeed;
|
||||
|
||||
// Clamp the FOV to be within the min and max zoom distances
|
||||
cam.fieldOfView = Mathf.Clamp(newFOV, minZoom, maxZoom);
|
||||
}
|
||||
}
|
||||
11
3D blobici/Assets/Scripts/Player/CameraZoom.cs.meta
Normal file
11
3D blobici/Assets/Scripts/Player/CameraZoom.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6ba5303a34820d54f953de5d92f56656
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
3D blobici/Assets/Scripts/Player/PlayerMovement.cs
Normal file
53
3D blobici/Assets/Scripts/Player/PlayerMovement.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerMovement : MonoBehaviour
|
||||
{
|
||||
public float moveSpeed = 5f;
|
||||
public float sprintSpeed = 10f;
|
||||
public float gravity = -9.81f;
|
||||
public float rotationSpeed = 10f;
|
||||
|
||||
private CharacterController controller;
|
||||
private Vector3 velocity;
|
||||
|
||||
void Start()
|
||||
{
|
||||
controller = GetComponent<CharacterController>();
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
HandleMovement();
|
||||
ApplyGravity();
|
||||
}
|
||||
|
||||
void HandleMovement()
|
||||
{
|
||||
float moveX = Input.GetAxisRaw("Horizontal");
|
||||
float moveZ = Input.GetAxisRaw("Vertical");
|
||||
Vector3 move = new Vector3(moveX, 0, moveZ).normalized;
|
||||
|
||||
if (move.magnitude >= 0.1f)
|
||||
{
|
||||
float currentSpeed = Input.GetKey(KeyCode.LeftShift) ? sprintSpeed : moveSpeed;
|
||||
|
||||
Quaternion targetRotation = Quaternion.LookRotation(move);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, rotationSpeed * Time.fixedDeltaTime);
|
||||
|
||||
controller.Move(move * currentSpeed * Time.fixedDeltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
void ApplyGravity()
|
||||
{
|
||||
if (IsGrounded() && velocity.y < 0) velocity.y = -2f;
|
||||
velocity.y += gravity * Time.fixedDeltaTime;
|
||||
controller.Move(velocity * Time.fixedDeltaTime);
|
||||
}
|
||||
|
||||
bool IsGrounded()
|
||||
{
|
||||
float groundDistance = 0.2f;
|
||||
return Physics.Raycast(transform.position, Vector3.down, groundDistance);
|
||||
}
|
||||
}
|
||||
11
3D blobici/Assets/Scripts/Player/PlayerMovement.cs.meta
Normal file
11
3D blobici/Assets/Scripts/Player/PlayerMovement.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f70538d2e61bdb4786c9b951596ecb9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
53
3D blobici/Assets/Scripts/Player/PlayerMovementJump.cs
Normal file
53
3D blobici/Assets/Scripts/Player/PlayerMovementJump.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerMovementJump : MonoBehaviour
|
||||
{
|
||||
public CharacterController charControl;
|
||||
|
||||
public float speed = 12f;
|
||||
public float gravity = -9.81f;
|
||||
public float jumpHeight = 3f;
|
||||
|
||||
|
||||
public Transform groundCheck;
|
||||
public float groundDistance = 0.4f;
|
||||
public LayerMask groundMask;
|
||||
|
||||
private Vector3 velocity;
|
||||
private bool isGrounded;
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
|
||||
|
||||
if(isGrounded && velocity.y < 0)
|
||||
{
|
||||
velocity.y = -2f;
|
||||
}
|
||||
|
||||
float x = Input.GetAxis("Horizontal");
|
||||
float y = Input.GetAxis("Vertical");
|
||||
|
||||
Vector3 move = transform.right * x + transform.forward * y;
|
||||
|
||||
charControl.Move(move * speed * Time.deltaTime);
|
||||
|
||||
if(Input.GetButtonDown("Jump") && isGrounded)
|
||||
{
|
||||
velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
|
||||
}
|
||||
|
||||
velocity.y += gravity * Time.deltaTime;
|
||||
|
||||
charControl.Move(velocity * Time.deltaTime);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
11
3D blobici/Assets/Scripts/Player/PlayerMovementJump.cs.meta
Normal file
11
3D blobici/Assets/Scripts/Player/PlayerMovementJump.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd49eadc2a40d404998ce4946886e88c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user