- Home /
Question by
viper667 · Dec 19, 2015 at 08:47 AM ·
arraysstringif-statements
How would I ensure "Weak" only has a value from 1-20, Strong would be 20-40, so on. It wont let me use an if statement
using UnityEngine; using System.Collections;
public class CreateNewPotion : MonoBehaviour {
private BasePotion newPotion;
private string[] itemName = new string[4] { "Weak", "Moderate", "Strong", "Full" };
void Start () {
CreatePotion();
Debug.Log(newPotion.ItemName);
Debug.Log(newPotion.PotionType.ToString());
Debug.Log(newPotion.Effect.ToString());
}
private void CreatePotion() {
newPotion = new BasePotion();
newPotion.ItemName = itemName[Random.Range(0, 3)];
newPotion.Effect = Random.Range(1, 101);
}
private void ChoosePotionType()
{
int randomTemp = Random.Range(1, 7);
if (randomTemp == 1)
{
newPotion.PotionType = BasePotion.PotionTypes.DAMAGE;
}else if (randomTemp == 2)
{
newPotion.PotionType = BasePotion.PotionTypes.HEALTH;
}
else if (randomTemp == 3)
{
newPotion.PotionType = BasePotion.PotionTypes.INVISIBILITY;
}
else if (randomTemp == 4)
{
newPotion.PotionType = BasePotion.PotionTypes.SPEED;
}
else if (randomTemp == 5)
{
newPotion.PotionType = BasePotion.PotionTypes.STAMINA;
}
else if (randomTemp == 6)
{
newPotion.PotionType = BasePotion.PotionTypes.STRENGTH;
}
}
}
Comment
ins$$anonymous$$d of having your itemName
consist of string
s, use a class which contains the name, $$anonymous$$ & max values.
also, ins$$anonymous$$d of those if
's in Choose PotionType()
, create an array of the potion type attributes and assign using a single line, unless you like typing ;)
Your answer
Follow this Question
Related Questions
comparing strings|easy way..... 2 Answers
Problem comparing contents of arrays 1 Answer
How to split a string into array? 2 Answers
String Arrays in a function 0 Answers