blob: 3df5e4b3b9ac9d12c7b3d7476fbd6b6ec5470e70 (
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
|
using mh;
using MH;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpiritScript : UnitBase
{
public float speed = 10f;
public Item_Coin coinPrefab;
public int count = 0;
private FastCircleCollider collider;
private static List<IQuadTreeObject> collisions = new List<IQuadTreeObject>();
protected override void Awake()
{
base.Awake();
collider = GetComponent<FastCircleCollider>();
}
protected override void Update()
{
base.Update();
UnitBase hero = UnitManager.hero;
Vector2 pos = transform.position;
Vector2 heroPos = hero.transform.position;
Vector2 dir = (heroPos - pos).normalized;
pos += dir * Time.deltaTime * speed;
this.GetComponent<SpriteRenderer>().flipX = dir.x < 0;
collisions.Clear();
if (TestQuadtree.quadtree.Retrieve(ref collisions, collider))
{
count = collisions.Count;
}
else
{
transform.position = pos;
}
}
public void Die()
{
Item_Coin coin = Instantiate(coinPrefab) as Item_Coin;
coin.transform.position = this.transform.position;
this.gameObject.SetActive(false);
Destroy(this.gameObject);
}
}
|