Question by
NohanG · Sep 28, 2015 at 06:37 AM ·
c#if-statementselse
Else section in if statement not executing?
I have an else section in my if statement. Do I need to be more specific and make it an if else with parameters or what? Here is the code. Because the else is being met in the situation I cooked up.
if (item.itemType != Item.ItemType.Ammo || item.itemType != Item.ItemType.Consumable || item.itemType != Item.ItemType.CraftingMaterial || item.itemType != Item.ItemType.QuestItem || item.itemType != Item.ItemType.Ring || item.itemType != Item.ItemType.Necklace) {
toolTipInformation.transform.GetChild (3).GetComponent<Text> ().text = "Durability: " + item.itemDurability;
} else {
toolTipInformation.transform.GetChild (3).GetComponent<Text> ().text = "";
}
Oh god it looks terrible
Comment
yes, it looks terrible ;)
you need to change your ||
's to &&
's
consider caching the Text
component too - GetComponent<>()
is relatively slow, so do it once in Awake()
or Start()
Your answer
Follow this Question
Related Questions
If statement being ignored 2 Answers
AudioSource in Update 1 Answer
Project Spark to C# - Started To, While, and No Longer 1 Answer
Laser System - "If" statement conflict 1 Answer
can't check if my NPC has a specific script attached 0 Answers