I’m looking for some help with the below code. The Debug shows the output fine for activecarda and activecardb but the problem is with the bottom section of the code, I cannot get it to show “matchfound”. I tried using && statement instead of nesting if statements, same issue. any ideas what i’m doing wrong?
if (this.tag==“card1”)
{
activecarda=1;
Debug.Log("activecarda "+activecarda);
}
if (this.tag==“card9”)
{
activecardb=9;
Debug.Log("activecardb "+activecardb);
}
//this is the problem below, doesnt print matchfound, tried using && loop but same issue
if (activecarda==1)
{
if (activecardb==9)
{
Debug.Log(“matchfound”);
}
}
Is all the code you pasted in the same function? Are activecarda and activecardb static? Can you show us the whole class? (Use the CODE tags!) I have a feeling the error is not in the code you have shown us but somewhere else.
I’ve manged to get it working, it was to do with the public variable, I thought I done it right by putting
public var activecarda
but had to put
static var activecarda
I think I’ll have to read up on how these variables work within functions as I have other variables declared which work fine within other functions which were declared the same way as activecarda and activecardb
Yeah, so you’ve attached the same script on different objects, just like @GarthSmith suggested.
The problem the two scripts had different booleans.
So one of the two booleans would always be false in any instance of the script.
Changing it to a static variable made it so the variable is shared over all instances.
People often use a manager script to save values that are supposed to be shared.
You’ll avoid making this mistake doing so, because there’s only supposed to be 1 instance of a manager script.