AI_WindAttack.cs 1.5 KB
Newer Older
mthiele2's avatar
mthiele2 committed
1
2
3
4
5
6
using UnityEngine;
using System.Collections.Generic;
using System.Collections;

public class AI_WindAttack : WeightedAction
{
mthiele2's avatar
mthiele2 committed
7
    GameObject target;
mthiele2's avatar
mthiele2 committed
8
9
10
11
12
13
14
15
16
	AI_Core myAI;

    private float restCooldown;
	private Rigidbody2D body;

	public GameObject windAttack;
	public float Cooldown;
    public float attackRange;
	public float firePower;
mthiele2's avatar
mthiele2 committed
17
18
19
	public int damage;
	public float destroyTime;
	public float thrust;
mthiele2's avatar
mthiele2 committed
20
21
22
23
24
25
26
27
28

    // Use this for initialization
    void Start()
    {
        myAI = GetComponent<AI_Core>();
    }

    void CheckConditions()
    {
mthiele2's avatar
mthiele2 committed
29
		if (myAI.rangeCheckFailed(transform, attackRange))
mthiele2's avatar
mthiele2 committed
30
31
32
33
34
35
36
37
38
		{
			return;
		}

		myAI.desiredAction.Add(this);
	}

    public override void performAction()
    {
mthiele2's avatar
mthiele2 committed
39
40
41
		target = GameObject.FindGameObjectWithTag("Player");

		Vector3 attackdir = target.transform.position - transform.position;
mthiele2's avatar
mthiele2 committed
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
        attackdir.Normalize();

        if (restCooldown <= 0)
        {
            Fire(attackdir);

            restCooldown = Cooldown;
        }
        else
        {
            restCooldown -= Time.deltaTime;
        }
    }

	public void Fire(Vector3 attackdir)
	{
mthiele2's avatar
mthiele2 committed
58
		GameObject projectile = Instantiate(windAttack, transform.position + attackdir*2, Quaternion.AngleAxis(0, Vector3.forward));
mthiele2's avatar
mthiele2 committed
59
		projectile.GetComponent<AI_WindProjectile>().setValues(damage, destroyTime, thrust);
mthiele2's avatar
mthiele2 committed
60
61
62
63
64
65

		body = projectile.GetComponent<Rigidbody2D>();
		Vector3 rotatedVector = Quaternion.AngleAxis(0, Vector3.forward) * attackdir;
		body.velocity = new Vector2(rotatedVector.x * firePower, rotatedVector.y * firePower);
	}
}