Newer
Older
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Tank : Fighter
{
[SerializeField, Tooltip("When the AntiPlayer is closer than this value, change to a combat idle anim")]
float playerNearDistance = 3.75f;
[SerializeField, Tooltip("How close the AntiPlayer has to be in order for this Bandit to start attacking")]
float playerDistanceToAttack = 1.25f;
GameObject antiPlayer;
SpriteRenderer spriteRenderer;
protected override void Awake()
{
base.Awake();
spriteRenderer = GetComponent<SpriteRenderer>();
antiPlayer = GameObject.FindGameObjectWithTag("AntiPlayer");
}
protected override void Update()
{
base.Update();
if (GetDistanceToAntiPlayer() < playerNearDistance)
{
animator.SetInteger("AnimState", 1); // Combat Idle
}
else
{
animator.SetInteger("AnimState", 0); // Idle
}
// animator.SetInteger("AnimState", 2); // Run
// Always face the AntiPlayer
spriteRenderer.flipX = transform.position.x < antiPlayer.transform.position.x;
}
protected override void Attack()
{
if (GetDistanceToAntiPlayer() < playerDistanceToAttack)
{
animator.SetTrigger("Attack");
}
}
float GetDistanceToAntiPlayer()
{
return Vector3.Distance(transform.position, antiPlayer.transform.position);
}
}