blob: d4db669f3a40fd63b1e0bd0c250c6f56c577fc51 (
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
|
using UnityEngine;
using System.Collections;
public class NewEnemyAttack : MonoBehaviour {
public bool PlayerInRange;
Rigidbody2D rb2d;
GameObject Player;
public Vector2 Origin;
NewEnemyTrigger trigger;
void Awake()
{
Player = GameObject.FindGameObjectWithTag("Player");
rb2d = GetComponent<Rigidbody2D>();
Origin = transform.position;
trigger = GetComponentInParent<NewEnemyTrigger>();
}
void Start ()
{
}
void Update ()
{
if (PlayerInRange)
{
rb2d.position = Vector2.MoveTowards(rb2d.position, Player.transform.position,0.1f);
}
else if(!PlayerInRange)
{
rb2d.position = Vector2.MoveTowards(rb2d.position, Origin, 0.1f);
}
}
void OnCollisionEnter2D(Collision2D col)
{
if (col.gameObject.GetComponentInParent<PlayerHealthScript>())
{
col.gameObject.GetComponentInParent<PlayerHealthScript>().TakeDamage(10);
PlayerInRange = false;
trigger.counter = 0;
}
}
}
|