Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Script variable question

I have a question. Is it necessary to put a script into an object in order to define public variables that we want then to refer to an object? For example if i write public GameObject character; , do i have to put this script on an object in order to drag and put the "character"?

Comments

  • GlaasGlaas Member

    Hi !

    It depends if your class derive from Monobehaviour. It it does, then your script won't do anything unless it's in a scene (and therefore attached to an object.

    However, you can have a script not sitting on an object using Scriptable Objects (https://docs.unity3d.com/Manual/class-ScriptableObject.html )

    but I don't think that what's you want.


    Also ; you can use static variables and classes if you want to access data without creating instances of it.

  • Ok. Thanks

Sign In or Register to comment.