Меню игрока и появление его при смерти

This commit is contained in:
2025-01-25 14:45:55 +03:00
parent c2bcb1ecd8
commit b2ecc77b2a
12 changed files with 4904 additions and 743 deletions

View File

@ -1,17 +1,39 @@
using System.Collections;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class HitDetectorScript : MonoBehaviour
{
private bool _IsDead = false;
[SerializeField] private GameObject _Menu;
[SerializeField] private GameObject _ForwardSource;
private void OnTriggerEnter(Collider other)
{
//Debug.Log(other.gameObject.name);
if (other.gameObject.CompareTag("Car"))
if (other.gameObject.CompareTag("Car") && !_IsDead)
{
_IsDead = true;
Vector3 pos = _ForwardSource.transform.position;
Vector3 forward = _ForwardSource.transform.forward;
// Определите расстояние перед объектом
float distance = 1.0f;
// Вычислите новую позицию с учетом расстояния
Vector3 newPos = pos + forward.normalized * distance;
// Меню смотрит в том же направлении, что и источник, но фиксируется по вертикали
Quaternion newRot = Quaternion.LookRotation(new Vector3(forward.x, 0, forward.z));
// Создание объекта
Instantiate(_Menu, newPos, newRot);
Debug.Log("Player was hitted car");
SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);
//SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().name);
}
}