From 766cdff5ffa72b65d7f106658d1603f47739b2ba Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Fri, 27 Oct 2023 11:05:14 +0800 Subject: + init --- GameCode/AttackLevel.cs | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 GameCode/AttackLevel.cs (limited to 'GameCode/AttackLevel.cs') diff --git a/GameCode/AttackLevel.cs b/GameCode/AttackLevel.cs new file mode 100644 index 0000000..78c92dd --- /dev/null +++ b/GameCode/AttackLevel.cs @@ -0,0 +1,53 @@ +using System; +using UnityEngine; + +public class AttackLevel : MonoBehaviour +{ + public int attackLevel = 1; + + public float levelScaleM = 0.7f; + + public Action LevelUpAction; + + private void Start() + { + SpawnedAttack componentInParent = GetComponentInParent(); + if ((bool)componentInParent) + { + attackLevel = componentInParent.attackLevel; + } + bool flag = false; + AttackLevel[] componentsInChildren = base.transform.root.GetComponentsInChildren(); + for (int i = 0; i < componentsInChildren.Length; i++) + { + if (!(componentsInChildren[i] == this) && componentsInChildren[i].gameObject.name == base.gameObject.name) + { + componentsInChildren[i].LevelUp(); + flag = true; + } + } + if (flag) + { + UnityEngine.Object.Destroy(base.gameObject); + } + } + + public float LevelScale() + { + return 1f + ((float)attackLevel - 1f) * levelScaleM; + } + + public int LevelsUp() + { + return attackLevel - 1; + } + + public void LevelUp() + { + attackLevel++; + if (LevelUpAction != null) + { + LevelUpAction(attackLevel); + } + } +} -- cgit v1.1-26-g67d0