using System; using System.Collections; using UnityEngine; namespace XRMultiplayer.MiniGames { /// /// Represents a projectile for the slingshot mini-game. /// public class SlingshotProjectile : Projectile { /// /// Event that is triggered when the local player hits a target with the projectile. /// public Action localPlayerHitTarget; /// /// The lifetime of the projectile. /// [SerializeField] float m_LifeTime = 10.0f; /// /// The collider for the projectile. /// [SerializeField] Collider m_Collider; /// /// The rigidbody for the projectile. /// [SerializeField] Rigidbody m_Rigidbody; /// /// Called before the first frame update. /// void Start() { Destroy(gameObject, m_LifeTime); } /// /// Launches the projectile with the specified parameters. /// /// The force to launch the projectile with. /// Indicates whether the player launching the projectile is the local player. /// The color of the player launching the projectile. public void LaunchProjectile(Vector3 launchForce, bool isLocalPlayer, Color playerColor) { Setup(isLocalPlayer, playerColor); m_Collider.enabled = false; m_Rigidbody.linearVelocity = launchForce; StartCoroutine(LaunchRoutine()); } /// /// Coroutine that enables the collider after a short delay. /// IEnumerator LaunchRoutine() { yield return new WaitForSeconds(.15f); m_Collider.enabled = true; } /// /// Called when the projectile hits a target. /// /// The target that was hit. protected override void HitTarget(Target target) { base.HitTarget(target); localPlayerHitTarget?.Invoke(this, target.targetValue); } } }