- Home /
Set ScriptType variable to current script?
Hey, this is kind of a silly question, but I was just wondering if there was any way you could set a ScriptType variable to the script currently being used to set said variable? Sort of like with this.gameObject, except instead I want this.ScriptName? It would save me from making a reference to itself and dragging the same script onto itself in the inspector. Thanks, I was just curious.
Answer by Hellium · Nov 20, 2018 at 06:08 AM
It's simply this, which refers to the current instance of the class. Thus, if in your class inheriting from MonoBehaviour, when you call this, you are refering to the instance of the script.
this.gameObject is possible because gameObject is an accessor inherited from the MonoBehaviour class (itself inherited from the`Component` class)
Converted your comment to answer, as this is the answer :)
Your answer
Follow this Question
Related Questions
Why when using get; set; in one script i'm getting null in other script that use it ? 1 Answer
How can i check and fire an event when the user look at specific object ? 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How can i first destroy twice the objects then to create twice the objects ? 1 Answer