summaryrefslogtreecommitdiff
path: root/Assets/Scripts/Player/Bullet.cs
blob: e96c2450eb60aa631f65860d07eb48beda54eabc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
        }
    }
}