如何解决Unity RPG状态表修复
当前要找到我的排名,您必须经过这一系列的if语句,我想知道是否有一种解决方案可以将其缩小为一遍,因此不是str,end,dex等。被一堆if传递,而是一个名为rank的列表,其中包含所有通过并显示该排名的属性。
[Range (0,999)]
public int strength;
[Range (0,999)]
public int endurance;
[Range (0,999)]
public int dexterity;
[Range (0,999)]
public int agility;
public int strengthRank;
public int enduranceRank;
public int dexterityRank;
public int agilityRank;
void Update () {
Rank ();
}
void Rank () {
strengthRank = (strength >= 0 && strength <= 99) ? 0 :
(strength >= 100 && strength <= 199) ? 1 :
(strength >= 200 && strength <= 299) ? 2 :
(strength >= 300 && strength <= 399) ? 3 :
(strength >= 400 && strength <= 499) ? 4 :
(strength >= 500 && strength <= 599) ? 5 :
(strength >= 600 && strength <= 699) ? 6 :
(strength >= 700 && strength <= 799) ? 7 :
(strength >= 800 && strength <= 899) ? 8 :
(strength >= 900 && strength <= 999) ? 9 : 0;
enduranceRank = (endurance >= 0 && endurance <= 99) ? 0 :
(endurance >= 100 && endurance <= 199) ? 1 :
(endurance >= 200 && endurance <= 299) ? 2 :
(endurance >= 300 && endurance <= 399) ? 3 :
(endurance >= 400 && endurance <= 499) ? 4 :
(endurance >= 500 && endurance <= 599) ? 5 :
(endurance >= 600 && endurance <= 699) ? 6 :
(endurance >= 700 && endurance <= 799) ? 7 :
(endurance >= 800 && endurance <= 899) ? 8 :
(endurance >= 900 && endurance <= 999) ? 9 : 0;
dexterityRank = (dexterity >= 0 && dexterity <= 99) ? 0 :
(dexterity >= 100 && dexterity <= 199) ? 1 :
(dexterity >= 200 && dexterity <= 299) ? 2 :
(dexterity >= 300 && dexterity <= 399) ? 3 :
(dexterity >= 400 && dexterity <= 499) ? 4 :
(dexterity >= 500 && dexterity <= 599) ? 5 :
(dexterity >= 600 && dexterity <= 699) ? 6 :
(dexterity >= 700 && dexterity <= 799) ? 7 :
(dexterity >= 800 && dexterity <= 899) ? 8 :
(dexterity >= 900 && dexterity <= 999) ? 9 : 0;
agilityRank = (agility >= 0 && agility <= 99) ? 0 :
(agility >= 100 && agility <= 199) ? 1 :
(agility >= 200 && agility <= 299) ? 2 :
(agility >= 300 && agility <= 399) ? 3 :
(agility >= 400 && agility <= 499) ? 4 :
(agility >= 500 && agility <= 599) ? 5 :
(agility >= 600 && agility <= 699) ? 6 :
(agility >= 700 && agility <= 799) ? 7 :
(agility >= 800 && agility <= 899) ? 8 :
(agility >= 900 && agility <= 999) ? 9 : 0;
我想知道我能否把它变成这样的东西
[Range (0,999)]
public int agility;
public int rank;
void Update () {
Rank ();
}
void Rank () {
rank = (x >= 0 && x <= 99) ? 0 :
(x >= 100 && x <= 199) ? 1 :
(x >= 200 && x <= 299) ? 2 :
(x >= 300 && x <= 399) ? 3 :
(x >= 400 && x <= 499) ? 4 :
(x >= 500 && x <= 599) ? 5 :
(x >= 600 && x <= 699) ? 6 :
(x >= 700 && x <= 799) ? 7 :
(x >= 800 && x <= 899) ? 8 :
(x >= 900 && x <= 999) ? 9 : 0;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。