Звук машин

This commit is contained in:
2025-01-25 16:18:02 +03:00
parent d9b9d51430
commit b194dc0191
18 changed files with 419 additions and 41 deletions

View File

@ -0,0 +1,53 @@
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") && !_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);
}
}
//private void OnCollisionEnter(Collision collision)
//{
// Debug.Log(collision.gameObject.name);
//}
//private void OnControllerColliderHit(ControllerColliderHit hit)
//{
// Debug.Log(hit.gameObject.name);
// if (hit.gameObject.CompareTag("Car"))
// {
// Debug.Log("Car hitted");
// }
//}
}