AI_WaterAttack.cs 1.06 KB
Newer Older
mthiele2's avatar
mthiele2 committed
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
using UnityEngine;

public class AI_WaterAttack : WeightedAction
{
	
    AI_Core myAI;

	Transform pos1, pos2;

	private bool movingRight;

	public float speed;
	public float distance;

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

    void CheckConditions()
	{
		myAI.desiredAction.Add(this);
    }

    public override void performAction()
    {
		transform.Translate(Vector2.right * Time.deltaTime * speed);

31
32
33
		RaycastHit2D groundInfo = Physics2D.Raycast(groundDetection.position, Vector3.down, distance, 1<<LayerMask.NameToLayer("Ground"));

		if (groundInfo.collider == false)
mthiele2's avatar
mthiele2 committed
34
		{
mthiele2's avatar
mthiele2 committed
35
			turn();
mthiele2's avatar
mthiele2 committed
36
37
		}
    }
mthiele2's avatar
mthiele2 committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51

	public void turn()
	{
		if (movingRight == true)
		{
			transform.eulerAngles = new Vector3(0, -180, 0);
			movingRight = false;
		}
		else
		{
			transform.eulerAngles = new Vector3(0, 0, 0);
			movingRight = true;
		}
	}
52
53
54
55
56
57

	private void OnDrawGizmos()
	{
		Gizmos.color = Color.red;
		Gizmos.DrawLine(groundDetection.position, groundDetection.position + Vector3.down * distance);
	}
mthiele2's avatar
mthiele2 committed
58
}