Звук машин
This commit is contained in:
53
Assets/Crossy Road VR/Scripts/HitDetectorScript.cs
Normal file
53
Assets/Crossy Road VR/Scripts/HitDetectorScript.cs
Normal 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");
|
||||
// }
|
||||
//}
|
||||
}
|
Reference in New Issue
Block a user