first commit
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class CameraFollow : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Transform target;
|
||||
[SerializeField] private Vector3 offset = new Vector3(0f, 18f, -10f);
|
||||
[SerializeField] private Vector3 rotationEuler = new Vector3(65f, 0f, 0f);
|
||||
[SerializeField] private float smoothSpeed = 8f;
|
||||
[SerializeField] private float rotationSmoothSpeed = 10f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Upgrade the old chase-camera setup to the new top-down view for existing scenes.
|
||||
if (offset == new Vector3(0f, 6f, -8f))
|
||||
{
|
||||
offset = new Vector3(0f, 18f, -10f);
|
||||
}
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 desiredPosition = target.position + offset;
|
||||
transform.position = Vector3.Lerp(transform.position, desiredPosition, smoothSpeed * Time.deltaTime);
|
||||
Quaternion desiredRotation = Quaternion.Euler(rotationEuler);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, desiredRotation, rotationSmoothSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c0a9f3e4d6c8b0123a4b5c6d7e8f102
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,32 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class Collectible : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private int scoreValue = 1;
|
||||
[SerializeField] private bool destroyOnPickup = true;
|
||||
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (!other.CompareTag("Player"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UIManager uiManager = FindObjectOfType<UIManager>();
|
||||
if (uiManager != null)
|
||||
{
|
||||
uiManager.AddScore(scoreValue);
|
||||
}
|
||||
|
||||
Debug.Log($"Collected {name} for {scoreValue} point(s).");
|
||||
|
||||
if (destroyOnPickup)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4d1b0a4f5e7d9c1234b5c6d7e8f10213
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class GoalZone : MonoBehaviour
|
||||
{
|
||||
private void OnTriggerEnter(Collider other)
|
||||
{
|
||||
if (!other.CompareTag("Player"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UIManager uiManager = FindObjectOfType<UIManager>();
|
||||
if (uiManager == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int requiredScore = uiManager.TargetScore;
|
||||
|
||||
if (uiManager.CurrentScore >= requiredScore)
|
||||
{
|
||||
uiManager.SetStatus("Цель достигнута");
|
||||
Debug.Log("Goal reached with enough collectibles.");
|
||||
}
|
||||
else
|
||||
{
|
||||
uiManager.SetStatus($"Нужно собрать больше сфер: {uiManager.CurrentScore}/{requiredScore}.");
|
||||
Debug.Log("Goal reached, but not enough collectibles yet.");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f3d2c61709f1e3456d7e8f102134567
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(Rigidbody), typeof(BoxCollider), typeof(PlayerInput))]
|
||||
public class Mover : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private float moveSpeed = 6f;
|
||||
[SerializeField] private float jumpForce = 7f;
|
||||
[SerializeField] private float groundCheckExtraDistance = 0.1f;
|
||||
|
||||
private Rigidbody rb;
|
||||
private BoxCollider boxCollider;
|
||||
private PlayerInput playerInput;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
boxCollider = GetComponent<BoxCollider>();
|
||||
playerInput = GetComponent<PlayerInput>();
|
||||
rb.freezeRotation = true;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
Vector3 moveDirection = playerInput.MoveInput;
|
||||
Vector3 targetVelocity = new Vector3(
|
||||
moveDirection.x * moveSpeed,
|
||||
rb.velocity.y,
|
||||
moveDirection.z * moveSpeed);
|
||||
|
||||
rb.velocity = targetVelocity;
|
||||
|
||||
if (moveDirection.sqrMagnitude > 0.001f)
|
||||
{
|
||||
transform.forward = moveDirection;
|
||||
}
|
||||
|
||||
if (playerInput.ConsumeJump() && IsGrounded())
|
||||
{
|
||||
rb.velocity = new Vector3(rb.velocity.x, 0f, rb.velocity.z);
|
||||
rb.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsGrounded()
|
||||
{
|
||||
Bounds bounds = boxCollider.bounds;
|
||||
float rayDistance = bounds.extents.y + groundCheckExtraDistance;
|
||||
return Physics.Raycast(bounds.center, Vector3.down, rayDistance, Physics.DefaultRaycastLayers, QueryTriggerInteraction.Ignore);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b9f8e2d3c5b7a9012f3a4b5c6d7e8f1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerInput : MonoBehaviour
|
||||
{
|
||||
public Vector3 MoveInput { get; private set; }
|
||||
public bool JumpPressed { get; private set; }
|
||||
|
||||
private void Update()
|
||||
{
|
||||
float horizontal = Input.GetAxisRaw("Horizontal");
|
||||
float vertical = Input.GetAxisRaw("Vertical");
|
||||
|
||||
MoveInput = new Vector3(horizontal, 0f, vertical).normalized;
|
||||
|
||||
if (Input.GetButtonDown("Jump"))
|
||||
{
|
||||
JumpPressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ConsumeJump()
|
||||
{
|
||||
if (!JumpPressed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
JumpPressed = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1a8f7e1d2c4b6a8091e2f3a4b5c6d7e8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Text scoreText;
|
||||
[SerializeField] private Text positionText;
|
||||
[SerializeField] private Text statusText;
|
||||
[SerializeField] private Transform player;
|
||||
[SerializeField] private int targetScore = 5;
|
||||
|
||||
public int CurrentScore { get; private set; }
|
||||
public int TargetScore => targetScore;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
UpdateScoreText();
|
||||
SetStatus($"Собери {targetScore} сфер и доберись до синей зоны.");
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (player == null || positionText == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 position = player.position;
|
||||
positionText.text = $"Position: X {position.x:F1} | Y {position.y:F1} | Z {position.z:F1}";
|
||||
}
|
||||
|
||||
public void AddScore(int amount)
|
||||
{
|
||||
CurrentScore += amount;
|
||||
UpdateScoreText();
|
||||
|
||||
if (CurrentScore < targetScore)
|
||||
{
|
||||
SetStatus($"Сфера собрана: {CurrentScore}/{targetScore}. Собери остальные.");
|
||||
return;
|
||||
}
|
||||
|
||||
SetStatus("Все сферы собраны. Двигайся к синей зоне.");
|
||||
}
|
||||
|
||||
public void SetStatus(string message)
|
||||
{
|
||||
if (statusText != null)
|
||||
{
|
||||
statusText.text = message;
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateScoreText()
|
||||
{
|
||||
if (scoreText != null)
|
||||
{
|
||||
scoreText.text = $"Spheres: {CurrentScore}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e2c1b506f8e0d2345c6d7e8f1021345
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user