AI_WindProjectile.cs 811 Bytes
Newer Older
mthiele2's avatar
mthiele2 committed
1
2
3
4
5
using UnityEngine;

public class AI_WindProjectile : MonoBehaviour
{

mthiele2's avatar
mthiele2 committed
6
7
8
9
    private float destroyTime;
	private float thrust;
	private int damage;

mthiele2's avatar
mthiele2 committed
10
11
12
13
14
15
16
    void Destroy()
    {
		Destroy(gameObject);
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
mthiele2's avatar
mthiele2 committed
17
18
19
20
		if (other.CompareTag("EnemyShot"))
		{
			return;
		}
mthiele2's avatar
mthiele2 committed
21
22
23
24
25
26
		if (other.CompareTag("Player"))
		{
			Vector2 dir = other.GetComponentInParent<Transform>().position - transform.position;
			dir.Normalize();
			dir *= thrust;
			other.attachedRigidbody.AddForce(dir, ForceMode2D.Impulse);
mthiele2's avatar
mthiele2 committed
27
			other.GetComponentInParent<Life>().Damage(damage);
mthiele2's avatar
mthiele2 committed
28
29
		}
		Destroy();
mthiele2's avatar
mthiele2 committed
30
31
32
33
34
35
36
37
38
	}

	public void setValues(int damage, float destroyTime, float thrust)
	{
		this.damage = damage;
		this.destroyTime = destroyTime;
		this.thrust = thrust;
		Invoke("Destroy", destroyTime);
	}
mthiele2's avatar
mthiele2 committed
39
40
41

}