init commit

This commit is contained in:
2026-04-30 12:04:09 +03:00
commit 8bd50d5e52
1714 changed files with 355124 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
using UnityEngine;
using UnityEngine.UI;
public class PlayerAmbientSound : MonoBehaviour
{
public AudioSource ambientSource; // åìᳺíò (ôîíîâà ìóçèêà)
public AudioSource cricketsSource; // ñâåð÷êè
public Slider volumeSlider;
void Start()
{
if (ambientSource != null)
{
ambientSource.loop = true;
ambientSource.Play();
}
if (cricketsSource != null)
{
cricketsSource.loop = true;
cricketsSource.Play();
}
if (volumeSlider != null)
{
volumeSlider.onValueChanged.AddListener(OnVolumeChange);
}
void OnVolumeChange(float value)
{
if (ambientSource != null)
ambientSource.volume = value;
if (cricketsSource != null)
cricketsSource.volume = value;
}
}
}

View File

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

View File

@@ -0,0 +1,120 @@
using UnityEngine;
using UnityEngine.InputSystem;
[RequireComponent(typeof(CharacterController))]
public class PlayerMovement : MonoBehaviour
{
public float playerSpeed = 10.0f;
private float earthSpeed = 10f;
private float jumpHeight = 2.5f;
private float gravityValue = -9.81f;
private CharacterController controller;
private Vector3 playerVelocity;
private bool groundedPlayer;
private float xRotation = 0f;
[Header("Input Actions")]
public InputActionReference moveAction;
public InputActionReference jumpAction;
[Header("Camera Settings")]
public Transform playerCamera;
public float mouseSensitivity = 3f;
[Header("Ground Checker")]
public Transform groundCheck;
public float groundDistance = 0.4f;
public LayerMask groundMask;
private void Awake()
{
controller = gameObject.GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Start()
{
SetPlayerRandomSpeed();
earthSpeed = playerSpeed;
}
private void OnEnable()
{
moveAction.action.Enable();
jumpAction.action.Enable();
}
private void OnDisable()
{
moveAction.action.Disable();
jumpAction.action.Disable();
}
void Update()
{
if (MenuController.Instance.isPaused) return;
MoveMouse();
PlayerJump();
MovePlayer();
}
private void MoveMouse()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity;
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -80f, 80f);
playerCamera.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
transform.Rotate(Vector3.up * mouseX);
}
private void PlayerJump()
{
groundedPlayer = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
if (groundedPlayer && playerVelocity.y < 0)
{
playerVelocity.y = 0f;
}
if (jumpAction.action.triggered && groundedPlayer)
{
playerVelocity.y = Mathf.Sqrt(jumpHeight * -2.0f * gravityValue);
}
}
private void MovePlayer()
{
float horizontal = Input.GetAxis("Horizontal");
float vertical = Input.GetAxis("Vertical");
Vector3 move = transform.right * horizontal + transform.forward * vertical;
controller.Move(move * playerSpeed * Time.deltaTime);
playerVelocity.y += gravityValue * Time.deltaTime;
controller.Move(playerVelocity * Time.deltaTime);
}
[ContextMenu("Set player random speed")]
public void SetPlayerRandomSpeed()
{
playerSpeed = Random.Range(8, 15);
earthSpeed = playerSpeed;
}
public void SetPlayerEarthSpeed()
{
playerSpeed = earthSpeed;
gravityValue = -9.81f;
}
public void SetPlayerLunarSpeed()
{
playerSpeed *= Mathf.Sqrt(1.62f / 9.81f);
gravityValue = -1.62f;
}
}

View File

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

View File

@@ -0,0 +1,41 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class PlayerRaycastOnUI : MonoBehaviour
{
public Camera playerCamera;
public Canvas worldCanvas;
public KeyCode interactKey = KeyCode.E;
private GraphicRaycaster raycaster;
private EventSystem eventSystem;
void Start()
{
raycaster = worldCanvas.GetComponent<GraphicRaycaster>();
eventSystem = EventSystem.current;
}
void Update()
{
// Ñòâîðþºìî PointerEventData íà îñíîâ³ öåíòðó êàìåðè
PointerEventData pointerData = new PointerEventData(eventSystem);
pointerData.position = playerCamera.WorldToScreenPoint(playerCamera.transform.position + playerCamera.transform.forward * 2f);
List<RaycastResult> results = new List<RaycastResult>();
raycaster.Raycast(pointerData, results);
foreach (var result in results)
{
Button button = result.gameObject.GetComponent<Button>();
if (button != null)
{
if (Input.GetKeyDown(interactKey))
{
button.onClick.Invoke();
}
}
}
}
}

View File

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