54 lines
1.0 KiB
C#
54 lines
1.0 KiB
C#
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.Rendering.Universal.Internal;
|
||
|
|
|
||
|
|
public class NPCAttack : MonoBehaviour
|
||
|
|
{
|
||
|
|
private float ATTACK_DISTANCE = 2.0f;
|
||
|
|
public float lastAttackTime = 0;
|
||
|
|
public float lastUpdateTime = 0;
|
||
|
|
|
||
|
|
private NPC npc;
|
||
|
|
|
||
|
|
public void Start()
|
||
|
|
{
|
||
|
|
npc = GetComponent<NPC>();
|
||
|
|
}
|
||
|
|
|
||
|
|
public void Update()
|
||
|
|
{
|
||
|
|
if (npc.isDead == true)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (Time.time - lastUpdateTime < 0.1f)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (Time.time - lastAttackTime < 1)
|
||
|
|
{
|
||
|
|
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (Player.Instance.IsAlive() == false)
|
||
|
|
{
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
Vector3 playerPosition = Player.Instance.transform.position;
|
||
|
|
|
||
|
|
if (Vector2.Distance(new Vector2(playerPosition.x, playerPosition.z), new Vector2(transform.position.x, transform.position.z)) < ATTACK_DISTANCE)
|
||
|
|
{
|
||
|
|
UIManager.Instance.showInterface("ScreenFlash");
|
||
|
|
AudioManager.Instance.playSound("player_hit");
|
||
|
|
PacketManager.sendNPCAttack(14);
|
||
|
|
lastAttackTime = Time.time;
|
||
|
|
}
|
||
|
|
|
||
|
|
lastUpdateTime = Time.time;
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|