- Home /
Accessing classes class from other script
If I'd use this type of script structure, is it possible to access class "Something" from other script, and like variable a?
public class Stuff : MonoBehaviour {
public class Something{
byte a=5;
}
}
I know, you can access the first-main class from other script using get component. But what about the second class?
Answer by deltamish · Jun 28, 2013 at 04:36 PM
Hi it is really simple to do just that
just the add this line to yor code
public class Stuff : MonoBehaviour {
public class Something{
byte a=5;
}
public Something Some;
}
public class ScriptB : MonoBehaviour {
Stuff StuffScript;
void Start(){
StuffScript = transform.GetComponent<Stuff>();
if(StuffScript)
StuffScript.Some.a = 1;///(Name of the script.Name of the class variable.value in the class)
}
}
Had to add public before byte a=5; though. :)
Thank you!
Answer by vcjr12 · Jun 28, 2013 at 04:33 PM
Yes, I think you should be able to. So for example if your in another script....
public class GetSomething ()
{
int numberOfBytes = Stuff.something.byte;
}
something similar like this should be able to work.
Your answer
Follow this Question
Related Questions
Can't get script to access other script/class (c#) 1 Answer
Storing a Class in a variable 1 Answer
Get GameObject name from other object. 2 Answers
Accessing another script from a class 3 Answers
Access other script from Editor script 2 Answers