blob: 69d3de13506bfea8697d679a8683d1abdbfcc2fe (
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
55
56
57
58
59
60
61
|
using UnityEngine;
using System.Collections;
public class Boss1AttackScript : MonoBehaviour {
GameObject player;
public float Damage = 20;
float timer = .5f;
float counter;
bool playerInRange;
bool active;
void Start()
{
counter = 0;
player = GameObject.FindGameObjectWithTag("Player");
}
void Update()
{
if (active)
{
counter += Time.deltaTime;
if (counter >= timer && playerInRange)
{
counter = 0f;
player.GetComponent<PlayerHealthScript>().TakeDamage(Damage);
}
}
}
void OnTriggerEnter2D(Collider2D other)
{
var player = other.gameObject.GetComponentInParent<PlayerHealthScript>();
if (player != null)
{
playerInRange = true;
}
}
void OnTriggerExit2D(Collider2D other)
{
var player = other.gameObject.GetComponentInParent<PlayerHealthScript>();
if (player != null)
{
playerInRange = false;
}
}
public void EnableBoss1Attack()
{
active = true;
}
public void DisableBoss1Attack()
{
active = false;
}
}
|