using System.Collections; using Unity.Netcode; using UnityEngine; namespace XRMultiplayer { /// /// Represents a target object in the target practice gameplay. /// public class Target : MonoBehaviour { /// /// The target value. /// public int targetValue = 1; /// /// The animator for the target. /// [SerializeField] Animator m_Animator; /// /// The collider for the target. /// [SerializeField] Collider m_TriggerCollider; /// /// The particle system for the target. /// [SerializeField] ParticleSystem m_Particles; /// /// The target manager for the target. /// TargetManager m_TargetManager; /// void Start() { m_TargetManager = GetComponentInParent(); } /// /// Enables the target object. /// public void EnableTarget() { m_Animator.SetTrigger("Activate"); m_TriggerCollider.enabled = true; } /// /// Handles the local target hit event. /// public void TargetHitLocal() { m_TargetManager.HitTargetServerRpc(NetworkManager.Singleton.LocalClientId, XRINetworkGameManager.LocalPlayerColor.Value); PlayHitEffects(XRINetworkGameManager.LocalPlayerColor.Value); } /// /// Handles the network target hit event. /// /// The ID of the client that hit the target. /// The color of the player who hit the target. public void TargetHitNetwork(ulong clientId, Color playerColor) { if (NetworkManager.Singleton.LocalClientId != clientId) { PlayHitEffects(playerColor); } if (m_TargetManager.IsServer) { StartCoroutine(TargetHitSequence()); } } /// /// Plays the hit effects for the target. /// /// void PlayHitEffects(Color playerColor) { m_Animator.SetTrigger("Hit"); m_TriggerCollider.enabled = false; var main = m_Particles.main; main.startColor = playerColor; m_Particles.Play(); StartCoroutine(HideAfterHit()); } IEnumerator HideAfterHit() { yield return new WaitForSeconds(3.0f); gameObject.SetActive(false); } /// /// Handles the target hit sequence. /// /// IEnumerator TargetHitSequence() { yield return new WaitForSeconds(2.25f); m_TargetManager.ServerIncreaseDifficulty(); } } }