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

183 lines
4.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-29 15:30:28 +08:00
// ö<>٣<EFBFBD><D9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public enum ElementType
{
Metal,
Wood,
Water,
Fire,
Earth
}
// ö<>٣<EFBFBD><D9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public enum DefenseType
{
HeavyArmor,//<2F>ؼ<EFBFBD>
LightArmor,//<2F><><EFBFBD><EFBFBD>
MagicShield,//ħ<><C4A7>
SpiritForm//<2F><><EFBFBD><EFBFBD>
}
// ö<>٣<EFBFBD><D9A3><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>
public enum UnitType
{
GroundUnit,//<2F><><EFBFBD>浥λ
AirUnit//<2F><><EFBFBD>е<EFBFBD>λ
}
// ö<>٣<EFBFBD><D9A3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
public enum Size
{
Small,//С
Large//<2F><>
}
2025-01-04 18:10:13 +08:00
public enum BulletAttackType
{
Shoot,//<2F><>
Pen,//<2F><>
Zhuan//ת
}
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;
2025-01-04 18:10:13 +08:00
[Header("<22><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٶ<EFBFBD>")] public BulletAttackType bulletAttackType;
2024-12-18 16:55:26 +08:00
[Header("<22>ƶ<EFBFBD><C6B6>ٶ<EFBFBD>")] public float moveSpeed;
2024-12-27 11:39:11 +08:00
[Header("<22><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7>")] public Sprite MengyaoSprite;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><CDBC>")] public List<Sprite> SkillSprites;
2024-12-27 17:13:20 +08:00
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;
2024-12-27 16:50:35 +08:00
//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>
2025-01-03 18:03:35 +08:00
public bool isSlowed = false; // <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD>״̬
2024-12-29 15:30:28 +08:00
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public float Defense;
// <20>ۼ<EFBFBD><DBBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿ<EFBFBD>ι<EFBFBD><CEB9><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˺<EFBFBD><CBBA><EFBFBD>
[Header("<22>ۼ<EFBFBD><DBBC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ")] public float DamageToPlayer;
// ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
[Header("ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ")] public float HealthPerLevel;
// ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2024-12-20 21:42:02 +08:00
2024-12-29 15:30:28 +08:00
[Header("ÿ<><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public float DefensePerLevel;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public ElementType elementType;
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public DefenseType defenseType;
2025-01-03 18:03:35 +08:00
2025-01-06 12:06:49 +08:00
[HideInInspector]
[Header("·<><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>")] public int index;
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>
2025-01-06 12:06:49 +08:00
Init(InitEnenyData.instance.GetRandomWaypoints(index));
2024-12-09 23:24:46 +08:00
}
}
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
}
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();
//<2F><>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD>
SpawnMonster.intance.enemysList.Remove(this.gameObject);
2025-01-07 16:27:10 +08:00
if (SpawnMonster.intance.enemysList.Count <= 0)
{
SpawnMonster.intance.Index += 1;
}
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)
{
2024-12-26 23:01:40 +08:00
//Debug.Log("<22><><EFBFBD><EFBFBD>------------------------");
2024-12-20 21:42:02 +08:00
// <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
}