- Home /
passing variables through scripts
Hello, i've got main code called head. It got inside:
public class head : MonoBehaviour
{
public static int lang = 0;
public static int score=0;
}
I want to connect two scripts to it - menu and deathScore
public class menu : MonoBehaviour
{
public int language = 0;
void Start()
{
head.language=language;//take language number from "head" script
}
}
and second script - deathScore
public class deathScore : MonoBehaviour
{
int hp=100;
void Update()
{
if(hp<=0)
{
head.score =+ 1;//add +1 to head's score
}
} }
and I've got errors:
Head: error CS0120: An object reference is required to access non-static member
menu.language' > Head error CS1061: Type
int' does not contain a definition forscore' and > no extension method
score' of type `int' could be found (are you missing a using directive or an assembly reference?)
What I did wrong?
For your first error, you name the variable 'lang' in head, not 'language'. For the second problem, are you posted the complete script? It is acting like you have an int variable named 'head' that is hiding the class.