Crossy_Road_VR/Assets/HitDetectorScript.cs

54 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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");
// }
//}
}