diff options
author | nirav <nirav@airmail.cc> | 2020-12-12 07:18:36 +0000 |
---|---|---|
committer | nirav <nirav@airmail.cc> | 2020-12-12 07:18:36 +0000 |
commit | 115f77bda0246a00f6e17469685c67746bdbd29d (patch) | |
tree | 4bbea1e59109bb1d1fddc71736f89289bab03073 /Assets/Scripts/Player/Bullet.cs | |
download | 01-master.tar.gz 01-master.zip |
Diffstat (limited to 'Assets/Scripts/Player/Bullet.cs')
-rwxr-xr-x | Assets/Scripts/Player/Bullet.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/Assets/Scripts/Player/Bullet.cs b/Assets/Scripts/Player/Bullet.cs new file mode 100755 index 0000000..e96c245 --- /dev/null +++ b/Assets/Scripts/Player/Bullet.cs @@ -0,0 +1,54 @@ +using UnityEngine; +using System.Collections; + +public class Bullet : MonoBehaviour { + + public float Speed = 10; + Vector2 Direction; + + GameObject Player; + + void Start () + { + Player = GameObject.FindGameObjectWithTag("Player") as GameObject; + if (Player.GetComponent<PlayerMovementScript>().FacingRight) + Direction = Vector2.right; + else + Direction = Vector2.left; + } + + void Update () + { + GetComponent<Rigidbody2D>().velocity = Direction * Speed; + + //Destroy after 2 seconds + Destroy(gameObject, 2f); + } + + void OnTriggerEnter2D(Collider2D col) + { + if(col.tag == "Enemy") + { + col.gameObject.GetComponent<EnemyHealthScript>().TakeDamage(25); + Destroy(gameObject); + } + + if (col.tag == "Enemy2") + { + col.gameObject.GetComponent<NewEnemyHealth>().TakeDamage(25); + Destroy(gameObject); + } + + if (col.tag == "Boss1") + { + col.gameObject.GetComponentInParent<Boss1HealthScript>().TakeDamage(25); + Destroy(gameObject); + } + + if (col.tag == "Enemy3") + { + col.gameObject.GetComponent<Enemy3HealthScript>().TakeDamage(25); + Destroy(gameObject); + } + } +} |