using System.Collections; using System.Collections.Generic; using UnityEngine; namespace BNG { public class ProjectileLauncher : MonoBehaviour { /// /// Launch this from the /// public GameObject ProjectileObject; public float ProjectileForce = 15f; public AudioClip LaunchSound; public ParticleSystem LaunchParticles; /// /// Where the projectile will launch from /// public Transform MuzzleTransform; private float _initialProjectileForce; // Start is called before the first frame update void Start() { // Setup initial velocity for launcher so we can modify it later _initialProjectileForce = ProjectileForce; } /// /// Returns the object that was shot /// /// The object that was shot public GameObject ShootProjectile(float projectileForce) { if (MuzzleTransform && ProjectileObject) { GameObject launched = Instantiate(ProjectileObject, MuzzleTransform.transform.position, MuzzleTransform.transform.rotation) as GameObject; launched.transform.position = MuzzleTransform.transform.position; launched.transform.rotation = MuzzleTransform.transform.rotation; launched.GetComponentInChildren().AddForce(MuzzleTransform.forward * projectileForce, ForceMode.VelocityChange); VRUtils.Instance.PlaySpatialClipAt(LaunchSound, launched.transform.position, 1f); if(LaunchParticles) { LaunchParticles.Play(); } return launched; } return null; } public void ShootProjectile() { ShootProjectile(ProjectileForce); } public void SetForce(float force) { ProjectileForce = force; } public float GetInitialProjectileForce() { return _initialProjectileForce; } } }