-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkill.cs
More file actions
57 lines (50 loc) · 1.22 KB
/
Skill.cs
File metadata and controls
57 lines (50 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class Skill
{
[SerializeField]
private int _level = 1;
public int Level
{
get => _level;
private set { if (value > _level) _level = value; }
}
[SerializeField]
private int _experience = 0;
public int Experience
{
get => _experience;
private set { _experience = value; }
}
public int MaxLevel { get; } = 10;
public int RequiredExperience()
{
if (Level < MaxLevel)
return 100 + 20 * (Level - 1);
else
return 1000;
}
public void AddExperience(int xp)
{
if (Level < MaxLevel)
{
Experience += xp;
while (Experience >= RequiredExperience())
{
Experience -= RequiredExperience();
LevelUp();
}
}
}
private void LevelUp()
{
Level++;
ApplyLevelUpEffect();
if (Level >= MaxLevel)
Experience = RequiredExperience() - 1;
}
protected virtual void ApplyLevelUpEffect() { }
}