Cute_demon_attacks/meng_yao/Assets/script/A_Fight/enemy.cs

129 lines
3.2 KiB
C#
Raw Normal View History

2024-12-08 02:52:59 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2024-12-08 04:55:59 +08:00
public class enemy : Role
2024-12-08 02:52:59 +08:00
{
2024-12-13 22:29:17 +08:00
public string enemyId;
2024-12-25 15:39:40 +08:00
2024-12-18 16:55:26 +08:00
[Header("<22>ƶ<EFBFBD><C6B6>ٶ<EFBFBD>")] public float moveSpeed;
2024-12-13 22:29:17 +08:00
[HideInInspector]
2024-12-20 21:42:02 +08:00
public float harmNumber = 0; // <20>˺<EFBFBD>
2024-12-13 22:29:17 +08:00
public float HarmNumber
{
2024-12-20 21:42:02 +08:00
get => harmNumber;
2024-12-13 22:29:17 +08:00
set
{
2024-12-20 21:42:02 +08:00
harmNumber = value;
Debug.Log(enemyId + "<22><><EFBFBD>˺<EFBFBD>" + harmNumber);
2024-12-13 22:29:17 +08:00
}
}
2024-12-20 21:42:02 +08:00
private float originalMoveSpeed; // <20><>¼<EFBFBD><C2BC>ʼ<EFBFBD><CABC><EFBFBD>ƶ<EFBFBD><C6B6>ٶ<EFBFBD>
private float slowDownTime = 0f; // <20><>¼<EFBFBD><C2BC><EFBFBD>ٿ<EFBFBD>ʼʱ<CABC><CAB1>
private bool isSlowed = false; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>״̬
2024-12-08 02:52:59 +08:00
public override void Start()
{
base.Start();
2024-12-18 16:55:26 +08:00
2024-12-20 21:42:02 +08:00
originalMoveSpeed = moveSpeed; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD>ƶ<EFBFBD><C6B6>ٶ<EFBFBD>
2024-12-08 04:55:59 +08:00
if (camp == Camp.Enemy)
{
2024-12-20 21:42:02 +08:00
if (AnimationTree != null)
2024-12-18 17:49:27 +08:00
{
2024-12-20 21:42:02 +08:00
AnimationTree[0].CharacterAnimationFrameInterval = (int)(36 / moveSpeed);
2024-12-18 17:49:27 +08:00
}
2024-12-20 21:42:02 +08:00
2024-12-09 18:01:59 +08:00
//<2F><>ʼ<EFBFBD>ƶ<EFBFBD>
2024-12-09 23:24:46 +08:00
Init(InitEnenyData.instance.GetRandomWaypoints());
}
}
public void Init(waypoints _waypoints)
{
base.Navigation.waypoints = _waypoints;
2024-12-20 21:42:02 +08:00
//<2F><>ʼ<EFBFBD>ƶ<EFBFBD>
Navigation.MoveToNextWaypoint(this.gameObject, moveSpeed);
2024-12-09 23:24:46 +08:00
}
public override void die()
{
2024-12-14 21:15:57 +08:00
base.die();
2024-12-09 23:24:46 +08:00
if (Application.isPlaying)
2024-12-20 21:42:02 +08:00
{
2024-12-10 00:58:59 +08:00
// <20><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0><EFBFBD>˶<EFBFBD><CBB6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-20 21:42:02 +08:00
if (SpawnPool.intance != null)
2024-12-10 06:57:53 +08:00
{
2024-12-20 21:42:02 +08:00
SkillBox.instance.AddExperience(6, this.gameObject.transform);
2024-12-09 23:24:46 +08:00
}
2024-12-10 00:58:59 +08:00
UIContorl.instance.Killnumber += 1;
2024-12-08 04:55:59 +08:00
}
2024-12-08 02:52:59 +08:00
}
2024-12-09 23:48:01 +08:00
2024-12-10 06:57:53 +08:00
private void OnTriggerEnter2D(Collider2D collision)
{
2024-12-20 21:42:02 +08:00
// <20><><EFBFBD>Χ<EBB7B6><CEA7><EFBFBD><EFBFBD>
2024-12-10 06:57:53 +08:00
if (this.camp == Camp.Enemy && collision.tag == "House")
{
UIContorl.instance.Hp -= 1;
2024-12-25 15:39:40 +08:00
UIContorl.instance.ShowRedMask();
2024-12-10 06:57:53 +08:00
Destroy(this.gameObject);
}
}
2024-12-20 21:42:02 +08:00
// <20><><EFBFBD>ٲ<EFBFBD><D9B2><EFBFBD>ָ<EFBFBD><D6B8>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ԭ<EFBFBD>ٶ<EFBFBD>
2024-12-25 11:23:00 +08:00
public override void SlowDown(float slowFactor, float duration)
2024-12-20 21:42:02 +08:00
{
if (!isSlowed)
{
Debug.Log("<22><><EFBFBD><EFBFBD>------------------------");
// <20><>ʱ<EFBFBD><CAB1><EFBFBD>ü<EFBFBD><C3BC>ٺ<EFBFBD><D9BA><EFBFBD><EFBFBD>ٶ<EFBFBD>
moveSpeed *= slowFactor;
// <20><><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƣ<EFBFBD><C6A3><EFBFBD><EFBFBD><EFBFBD><C2B6><EFBFBD><EFBFBD>ٶ<EFBFBD>
if (AnimationTree != null)
{
AnimationTree[0].CharacterAnimationFrameInterval = (int)(36 / moveSpeed);
}
Navigation.ChangeSpeed(slowFactor, duration);
// <20><><EFBFBD>Ǽ<EFBFBD><C7BC><EFBFBD>״̬
isSlowed = true;
// <20><>¼<EFBFBD><C2BC><EFBFBD>ٿ<EFBFBD>ʼʱ<CABC><CAB1>
slowDownTime = Time.time;
}
}
void Update()
{
if (isSlowed)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
if (Time.time - slowDownTime >= 3f) // 3<><33><EFBFBD><EFBFBD><EFBFBD>ָ<EFBFBD>ԭ<EFBFBD>ٶ<EFBFBD>
{
// <20>ָ<EFBFBD><D6B8><EFBFBD>ʼ<EFBFBD>ٶ<EFBFBD>
moveSpeed = originalMoveSpeed;
// <20>ָ<EFBFBD><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>
if (AnimationTree != null)
{
foreach (var anim in AnimationTree)
{
anim.CharacterAnimationFrameInterval = (int)(36 / moveSpeed);
}
}
// ȡ<><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬
isSlowed = false;
}
}
}
2024-12-08 02:52:59 +08:00
}