start work on implementing gameplay
This commit is contained in:
parent
94f5a5e209
commit
274af1e5a1
42 changed files with 3054 additions and 371 deletions
31
Assets/Scripts/Projectile.cs
Normal file
31
Assets/Scripts/Projectile.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class Projectile : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private Rigidbody2D rb;
|
||||
public int damage;
|
||||
public float speed;
|
||||
public float lifetime;
|
||||
public Vector2 direction;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Destroy(gameObject, lifetime);
|
||||
direction = transform.right;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
rb.linearVelocity = direction * speed;
|
||||
}
|
||||
|
||||
private void OnTriggerEnter2D(Collider2D other)
|
||||
{
|
||||
if (!other.CompareTag(tag) && other.TryGetComponent(out Entity isEntity))
|
||||
{
|
||||
isEntity.TakeDamage(damage);
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue