diff options
author | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-10-27 11:05:14 +0800 |
commit | 766cdff5ffa72b65d7f106658d1603f47739b2ba (patch) | |
tree | 34d7799a94dfa9be182825577583c0fa6dc935f7 /GameCode/AttackLevel.cs |
+ init
Diffstat (limited to 'GameCode/AttackLevel.cs')
-rw-r--r-- | GameCode/AttackLevel.cs | 53 |
1 files changed, 53 insertions, 0 deletions
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<int> LevelUpAction; + + private void Start() + { + SpawnedAttack componentInParent = GetComponentInParent<SpawnedAttack>(); + if ((bool)componentInParent) + { + attackLevel = componentInParent.attackLevel; + } + bool flag = false; + AttackLevel[] componentsInChildren = base.transform.root.GetComponentsInChildren<AttackLevel>(); + 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); + } + } +} |