-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShootableMonster.cs
More file actions
43 lines (35 loc) · 1.11 KB
/
ShootableMonster.cs
File metadata and controls
43 lines (35 loc) · 1.11 KB
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
using UnityEngine;
using System.Collections;
public class ShootableMonster : Monster
{
[SerializeField]
private float rate = 2.0F;
[SerializeField]
private Color bulletColor = Color.white;
private Bullet bullet;
protected override void Awake()
{
bullet = Resources.Load<Bullet>("Bullet");
}
protected override void Start()
{
InvokeRepeating("Shoot", rate, rate);
}
private void Shoot()
{
Vector3 position = transform.position; position.y += 0.5F;
Bullet newBullet = Instantiate(bullet, position, bullet.transform.rotation) as Bullet;
newBullet.Parent = gameObject;
newBullet.Direction = -newBullet.transform.right;
newBullet.Color = bulletColor;
}
protected override void OnTriggerEnter2D(Collider2D collider)
{
Unit unit = collider.GetComponent<Unit>();
if (unit && unit is Character)
{
if (Mathf.Abs(unit.transform.position.x - transform.position.x) < 0.3F) ReceiveDamage();
else unit.ReceiveDamage();
}
}
}