I know it’s been asked like one million times but i’ve done research and i KNOW how to do it in JAVASCRIPT but now i need to do it in C# and i use the same method but written in c# ofc, and it doesnt work…
I’ve looked over GetComponent in c# and other unity posts but still ERRORS
Help please im stuck
public Grayscale grayScaleScript;
public float Health;
void Start ()
{
grayScaleScript = GameObject.Find ("Player").GetComponent<Grayscale> ();
}
void Update ()
{
if(Health =< 50)
{
grayScaleScript.enabled = true;
}
}
public Grayscale grayScaleScript;
public float Health;
protected void Awake()
{
// Pretty dirty, but does the trick
// Avoid using FindObjectOfType, because it's really inefficient
// Best practive is to create a "Player" script and find the player by type, then do a getComponentInChildren<Grayscale>() on the player
grayScaleScript = FindObjectOfType<Grayscale>();
}
protected void Update()
{
if (Health =< 50)
{
grayScaleScript.enabled = true;
}
}
I have just perform a quick test and it works for me… except that (Health =< 50) doesn’t compile (I suppose it’s “<=” in your code).