Implemented Bullet component
Added Death() method to AbstractCharacter Implemented basic bullet collision detection and effect
This commit is contained in:
parent
98402a90f7
commit
37e8c8d689
3 changed files with 60 additions and 8 deletions
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
@ -93,9 +94,24 @@ public abstract class AbstractCharacter : MonoBehaviour
|
||||||
public abstract void Move(Vector2 movementDirection);
|
public abstract void Move(Vector2 movementDirection);
|
||||||
public abstract void Shoot();
|
public abstract void Shoot();
|
||||||
|
|
||||||
// TODO : Manage hurt + OnCollision + Death'n stuff
|
private void OnCollisionEnter2D(Collision2D other)
|
||||||
public void Hurt()
|
|
||||||
{
|
{
|
||||||
throw new System.NotImplementedException();
|
Bullet bullet = other.gameObject.GetComponent<Bullet>();
|
||||||
|
if (bullet == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Hurt(bullet.Damage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Hurt(int damage)
|
||||||
|
{
|
||||||
|
CurrentHealth -= damage;
|
||||||
|
if (CurrentHealth <= 0)
|
||||||
|
{
|
||||||
|
Death();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Handles the death of the character, should be overriden
|
||||||
|
protected abstract void Death();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,38 @@
|
||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class Bullet : MonoBehaviour
|
public class Bullet : MonoBehaviour
|
||||||
{
|
{
|
||||||
// Start is called before the first frame update
|
[SerializeField] private int _damage;
|
||||||
void Start()
|
public int Damage => _damage;
|
||||||
|
|
||||||
|
// Speed in m/s
|
||||||
|
[SerializeField] private float _speed;
|
||||||
|
public float Speed
|
||||||
{
|
{
|
||||||
|
get { return _speed; }
|
||||||
|
set { _speed = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
[SerializeField] private Vector2 _direction;
|
||||||
|
public Vector2 Direction
|
||||||
|
{
|
||||||
|
get { return _direction; }
|
||||||
|
set { _direction = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
Mover mover = GetComponentInParent<Mover>();
|
||||||
|
if (mover == null)
|
||||||
|
{
|
||||||
|
throw new MissingComponentException("Missing Mover!");
|
||||||
|
}
|
||||||
|
|
||||||
|
mover.Direction = Direction;
|
||||||
|
mover.MaxSpeed = Speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
|
@ -15,4 +40,10 @@ public class Bullet : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destroy on Stay, collision effects should be handled on Enter
|
||||||
|
private void OnCollisionStay2D(Collision2D other)
|
||||||
|
{
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,4 +17,9 @@ public class PlayerCharacter : AbstractCharacter
|
||||||
// TODO : Implement
|
// TODO : Implement
|
||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void Death()
|
||||||
|
{
|
||||||
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue