Добавлено меню с отказом от претензий

This commit is contained in:
2025-01-30 14:35:02 +03:00
parent 2ded056af2
commit b9c7bcb22f
18 changed files with 3841 additions and 39 deletions

View File

@ -0,0 +1,73 @@
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerJumpScript : MonoBehaviour
{
[SerializeField] private InputActionProperty _JumpButton;
[SerializeField] private float _JumpHeight = 0f; // Высота прыжка
[SerializeField] private CharacterController _CharacterController;
[SerializeField] private LayerMask _GroundLayers;
[SerializeField] private float rad = 0;
private float _verticalVelocity = 0f; // Вертикальная скорость
private float _gravity = Physics.gravity.y; // Гравитация
private bool _isGrounded;
private void Update()
{
_isGrounded = IsGrounded();
//if (_JumpButton.action.WasPressedThisFrame())
//{
// if (_isGrounded)
// {
// Debug.Log("Will Jump from gruond");
// }
// else
// {
// Debug.Log("Not Jump");
// }
//}
// Если персонаж на земле, обнуляем вертикальную скорость и проверяем прыжок
if (_isGrounded)
{
_verticalVelocity = -1f; // Небольшое значение, чтобы персонаж не зависал в воздухе
// Если кнопка прыжка нажата
if (_JumpButton.action.WasPressedThisFrame())
{
Jump();
}
}
else
{
// Применяем гравитацию, если персонаж не на земле
_verticalVelocity += _gravity * Time.deltaTime;
}
// Перемещение персонажа с учетом вертикальной скорости
Vector3 movement = new Vector3(0, _verticalVelocity, 0);
if (_CharacterController.enabled == true)
{
_CharacterController.Move(movement * Time.deltaTime);
}
}
private bool IsGrounded()
{
return Physics.CheckSphere(transform.position, rad, _GroundLayers); // Радиус может быть отрегулирован
}
private void Jump()
{
if (_isGrounded)
{
// Применяем силу прыжка
_verticalVelocity = Mathf.Sqrt(_JumpHeight * -2f * _gravity); // Формула для прыжка с заданной высотой
}
}
}

View File

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

View File

@ -0,0 +1,32 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(AudioSource))]
public class RandomMusicSelectScript : MonoBehaviour
{
[SerializeField] List<AudioClip> _MusicClipList;
private AudioSource _Audio;
// Start is called before the first frame update
void Start()
{
_Audio = GetComponent<AudioSource>();
_Audio.clip = GetRandomObject<AudioClip>(_MusicClipList);
_Audio.Play();
}
T GetRandomObject<T>(List<T> list)
{
// проверка на пустоту списка
if (list == null || list.Count == 0)
{
return default;
}
// Генерация случайного индекса
int randomIndex = UnityEngine.Random.Range(0, list.Count);
return list[randomIndex];
}
}

View File

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

View File

@ -0,0 +1,127 @@
using System.Collections.Generic;
using UnityEngine;
public class SpawnRandomObjectsScript : MonoBehaviour
{
[SerializeField] private List<GameObject> _Prefabs = new List<GameObject>();
[SerializeField] private Vector3 _SpawnArea;
[SerializeField] private float fixedDistance = 1f; // фиксированное расстояние между точками
private float MinX; // минимальная координата X
private float MaxX; // максимальная координата X
private float MinZ; // минимальная координата Z
private float MaxZ; // максимальная координата Z
private float Y;
// кол-во повторных проходов
[SerializeField] private int NumOfRep = 1;
// Структура Point теперь на плоскости X-Z
// Структура Point теперь на плоскости X-Z
public struct Point
{
public Vector3 Position; // позиция точки
public Point(float x, float y, float z)
{
Position = new Vector3(x, y, z); // плоскость 2D, Y-координата всегда 0
}
public float DistanceTo(Point other)
{
return Vector3.Distance(Position, other.Position); // возвращаем расстояние между точками
}
}
private List<Point> points = new List<Point>();
void Start()
{
MinX = -_SpawnArea.x / 2 + transform.position.x;
MaxX = _SpawnArea.x / 2 + transform.position.x;
MinZ = -_SpawnArea.z / 2 + transform.position.z;
MaxZ = _SpawnArea.z / 2 + transform.position.z;
Y = -_SpawnArea.y / 2 + transform.position.y;
GeneratePoints();
foreach (var point in points)
{
GameObject prefab = GetRandomObject<GameObject>(_Prefabs);
// Случайный поворот только по оси Y
Quaternion randomRotation = Quaternion.Euler(
0f, // угол по оси X
Random.Range(0f, 360f), // случайный угол по оси Y
0f // угол по оси Z
);
// Инстанцируем объект с случайным поворотом
Transform child = Instantiate(prefab, point.Position, randomRotation).transform;
child.SetParent(transform);
}
}
public void GeneratePoints()
{
// Размещение первой точки случайным образом в указанном диапазоне
points.Add(new Point(Random.Range(MinX, MaxX), Y, Random.Range(MinZ, MaxZ)));
for (int i = 0; i < NumOfRep; i++)
{
bool canAddPoint = true;
while (canAddPoint)
{
canAddPoint = false;
// Пробуем случайно разместить следующую точку в пределах нового диапазона
float newX = Random.Range(MinX, MaxX);
float newZ = Random.Range(MinZ, MaxZ);
Point newPoint = new Point(newX, Y, newZ);
bool valid = true;
foreach (var point in points)
{
if (newPoint.DistanceTo(point) < fixedDistance) // фиксированное расстояние
{
valid = false;
break;
}
}
// Если точка валидна (удовлетворяет условиям), добавляем её
if (valid)
{
points.Add(newPoint);
canAddPoint = true;
}
}
}
}
void OnDrawGizmos()
{
// Устанавливаем цвет Gizmos
Gizmos.color = Color.red;
// Рисуем сферу
Gizmos.DrawWireCube(transform.position, _SpawnArea);
}
T GetRandomObject<T>(List<T> list)
{
// проверка на пустоту списка
if (list == null || list.Count == 0)
{
return default;
}
// Генерация случайного индекса
int randomIndex = UnityEngine.Random.Range(0, list.Count);
return list[randomIndex];
}
}

View File

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

View File

@ -82,7 +82,7 @@ public class TileManagerScript : MonoBehaviour
//_PlayerSetup.SetActive(true);
_PlayerSetup.SetActive(true);
}
/// <summary>