Not entirely sure what to ask so forgive the title.
Preamble
I have an ability on my player that highlights enemies for a brief time, all works well for this.
I decided to make this upgradable so the higher the level of the ability the more stuff gets highlighted.
- Level 0 (base level) enemies are highlighted.
- Level 1 enemies & Items are highlighted.
- Level 2 enemies, items & special items are highlighted.
- Level 3 enemies, items, special items & hidden areas are highlighted.
To do this I thought a switch running in an IEnumerator (Coroutine) would be the most efficient way. A function calls the coroutine and depending on the level the player has for the ability a switch should handle the the actual ability functionality (see code).
Here's the code.
public void CatsEye(){
if (player.cateye >= 1 && !catsEyeActive) {
player.cateye -= 1;
StartCoroutine("CatEye");
// Debug.Log("Cateye Active");
}
}
IEnumerator CatEye(){
catsEyeActive = true;
switch(player.cateyeLevel){
case 3:
if (itemObject != null && enemyObject != null
&& specialObject != null && hiddenObject != null) {
hidden.isOutlined = true;
special.isOutlined = true;
enemyData.isOutlined = true;
item.isOutlined = true;
}
yield return new WaitForSeconds(15f);
if (itemObject != null && enemyObject != null) {
hidden.isOutlined = false;
special.isOutlined = false;
enemyData.isOutlined = false;
item.isOutlined = false;
}
catsEyeActive = false;
break;
case 2:
if (itemObject != null && enemyObject != null && specialObject != null) {
special.isOutlined = true;
enemyData.isOutlined = true;
item.isOutlined = true;
}
yield return new WaitForSeconds(15f);
if (itemObject != null && enemyObject != null) {
special.isOutlined = false;
enemyData.isOutlined = false;
item.isOutlined = false;
}
catsEyeActive = false;
break;
case 1:
if (itemObject != null && enemyObject != null) {
enemyData.isOutlined = true;
item.isOutlined = true;
}
yield return new WaitForSeconds(15f);
if (itemObject != null && enemyObject != null) {
enemyData.isOutlined = false;
item.isOutlined = false;
}
catsEyeActive = false;
break;
case 0:
if (enemyObject != null) {
enemyData.isOutlined = true;
}
yield return new WaitForSeconds(15f);
if (enemyObject != null) {
enemyData.isOutlined = false;
}
catsEyeActive = false;
break;
}
}
The Issue
Is that even with the player.cateyeLevel set at 0 the ability is acting as if it's at level 3 and is highlighting everything. The player.cateyeLevel refers to a player script but there are no variables set there that would be the cause of the issue, in fact, if anything the player.cateyeLevel variable for this ability has been set to 0. There's also no PlayerPrefs storing the player.cateyeLevel so it isn't that either.Anyone got any ideas?
Thanks in advance.