Projectile Hit Sound Added
This commit is contained in:
@@ -6,21 +6,24 @@ namespace AI
|
||||
[RequireComponent(typeof(Rigidbody2D))]
|
||||
public class Projectile : MonoBehaviour, IPausable
|
||||
{
|
||||
private Rigidbody2D _rigidbody = null;
|
||||
public Rigidbody2D Rigidbody { get; private set; } = null;
|
||||
private AudioSource audioSource = null;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody2D>();
|
||||
Rigidbody = GetComponent<Rigidbody2D>();
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
}
|
||||
|
||||
public void SetVelocity(Vector2 velocity)
|
||||
{
|
||||
_rigidbody.velocity = velocity;
|
||||
Rigidbody.velocity = velocity;
|
||||
}
|
||||
|
||||
private void OnCollisionEnter2D(Collision2D other)
|
||||
{
|
||||
ProjectilePool.Instance.Return(this);
|
||||
audioSource.Play();
|
||||
|
||||
if (other.transform.CompareTag("Player"))
|
||||
other.gameObject.GetComponent<Player.Death>().Die();
|
||||
@@ -41,7 +44,7 @@ namespace AI
|
||||
|
||||
private void UpdateRigidbody()
|
||||
{
|
||||
_rigidbody.simulated = !IsPaused;
|
||||
Rigidbody.simulated = !IsPaused;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -42,14 +42,16 @@ namespace AI
|
||||
if (projectile == null)
|
||||
projectile = Instantiate(prefab).GetComponent<Projectile>();
|
||||
|
||||
projectile.gameObject.SetActive(true);
|
||||
projectile.transform.position = Vector3.left * 10000;
|
||||
projectile.Rigidbody.simulated = true;
|
||||
|
||||
return projectile;
|
||||
}
|
||||
|
||||
public void Return(Projectile projectile)
|
||||
{
|
||||
projectile.gameObject.SetActive(false);
|
||||
projectile.Rigidbody.simulated = false;
|
||||
projectile.transform.position = Vector3.right * 10000;
|
||||
pool.Push(projectile);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user