Добавлен гудок машинам

This commit is contained in:
2025-01-31 14:00:16 +03:00
parent 7dcd08212d
commit 64d5577fd8
19 changed files with 1588 additions and 13 deletions

View File

@ -1,5 +1,4 @@
using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
@ -25,15 +24,57 @@ public class CarControllerScript : MonoBehaviour
[SerializeField]
private float _High;
[SerializeField]
private CarBipScript _PlayerDetect;
[SerializeField]
private AudioSource _CarBip;
HitDetectorScript _HitDetector;
public float High
{
get => _High;
set => _High = value;
}
private bool _IsBeep = false;
private void Start()
{
_High = gameObject.transform.position.y;
_PlayerDetect.PlayerEntered.AddListener(StartBeep);
_PlayerDetect.PlayerExited.AddListener(StopBeep);
}
private void StartBeep(HitDetectorScript hit)
{
_HitDetector = hit;
_HitDetector.Dead.AddListener(StopBeep);
if (!_IsBeep && !_HitDetector.IsDead)
{
_CarBip.Play();
_IsBeep = true;
}
}
private void StopBeep()
{
if (_IsBeep)
{
_CarBip.Stop();
_IsBeep = false;
}
}
private void StopBeep(HitDetectorScript hit)
{
_HitDetector = hit;
if (_IsBeep)
{
_CarBip.Stop();
_IsBeep= false;
}
}
private void FixedUpdate()
@ -44,5 +85,4 @@ public class CarControllerScript : MonoBehaviour
}
}
}

View File

@ -1,9 +1,15 @@
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.XR.Interaction.Toolkit;
using static UnityEngine.XR.OpenXR.Features.Interactions.DPadInteraction;
public class HitDetectorScript : MonoBehaviour
{
private bool _IsDead = false;
public bool IsDead
{
get { return _IsDead; }
}
[SerializeField] private GameObject _Menu;
[SerializeField] private GameObject _ForwardSource;
@ -17,6 +23,8 @@ public class HitDetectorScript : MonoBehaviour
[SerializeField] XRBaseController _LeftController;
[SerializeField] XRBaseController _RightController;
public UnityEvent Dead = new UnityEvent();
private void OnTriggerEnter(Collider other)
{
//Debug.Log(other.gameObject.name);
@ -24,6 +32,8 @@ public class HitDetectorScript : MonoBehaviour
{
_IsDead = true;
Dead.Invoke();
move.enabled = false;
_CharacterController.enabled = false;