gabrielcrowe
7/22/2019 - 9:48 AM

Unity Get Class Variable

Gets a variable from a class sttached to an object, in this example we get it using a collider.

    void OnCollisionEnter(Collision col)
    {

        if (col.gameObject != null && col.gameObject.GetComponent<variableFromClass>() != null)
        {
            Debug.Log(col.gameObject.GetComponent<variableFromClass>().variableName);
        }
 
    }