how to see if two string are the same (I just what to see if Magicsetom[x] is == to boxadd )
private string[] MagicNameloder;
[SerializeField] private string boxadd;
void Start()
{
MagicNameloder[0]="name1";
MagicNameloder[1]="name2";
MagicNameloder[2]="name3";
}
void Update()
{
boxadd="Name"+math.Random.Range(1f, 3f);
for (int x = 0; x < magicsetom.Length; x++)
{
string Test = magicsetom[x];
if (boxadd !="")
{
if (x % 2 != 0)
{
if (Test== boxadd)
{
Debug.Log("" + Test + "==" + "" + boxadd);
Instantiate(Resources.Load("Magic/" + MagicNameloder[x + 1]),
player.transform.position, Quaternion.identity);
}
else if (Test. != boxadd)
{
Debug.Log("" + Test + "!=" + "" + boxadd);
}
}
}
}
}
Answer by dorusoftware · Jul 24, 2020 at 08:31 PM
This:
boxadd="Name"+math.Random.Range(1f, 3f);
will probably never land on 1f, 2f or 3f as the generated number will be something like 1.04532324f or 0.45382f or 2.4393234f
then even if it will ever land of 2f there is a chance that the resulting string will be "Name1.0f" or similar.
if you want to have three random values 1, 2 and 3 then you need to generate a random int number not a float
that makes sense. Thank you for help I found out what went wrong if you what to see my code that I was work. I hade to dumb it down because it was to long and to complex. You can find it at https://answers.unity.com/questions/1754508/cant-get-if-stringequalsmagicsetomx-boxadd-working.html
Answer by pmurph03 · Jul 23, 2020 at 11:06 PM
Try to debug.log boxadd and see if it actually matches name1 or name2 or name3. Should help you find your issue.
Your answer
Follow this Question
Related Questions
How to get the active/loaded Scene then turn the name of it into a string? [C#] 1 Answer
Changing GUI Text to int and applying operands 1 Answer
Display string in the UI text in specific format 1 Answer
Developer Console problems..... (in-game console) 0 Answers
Error FormatException: Input string was not in a correct format. 0 Answers