jeudi 16 avril 2015

Access a non-MonoBehaviour script from another script (Unity)

I'm working on a Unity project and i would like to access a non MonoBehaviour script from another script. I can't use GetComponent cause the script isn't MonoBehabiour, is there a solution ? Here is some code to help you understand :



public class SomeClass {
public static float coolVar = 1.0f;


public class AnotherClass {
// i want to be able to access coolVar and change her value
// i know i can do SomeClass.coolVar but i was looking for another way close to a GetComponent approach


My SomeClass class is full of static var i need to edit, i didn't implemented those variables and i can't modify them (i know it's bad practices).


Maybe the reflection is the best way :



typeof(SomeClasse).GetField(name).SetValue(null, value);





Aucun commentaire:

Enregistrer un commentaire