K
K
knechtruprecht2022-03-06 11:19:05
C++ / C#
knechtruprecht, 2022-03-06 11:19:05

How to use a variable from another script?

It's simple, there are two scripts. One of them contains a variable that I want to use in the other.
How can I access a variable from another script?

thank you*

Answer the question

In order to leave comments, you need to log in

3 answer(s)
H
HemulGM, 2022-03-06
@HemulGM

Learn programming, here's how

K
kirillbeliy, 2022-03-06
@kirillbeliy

If I'm not mistaken, create an object of the class (script) and use it to access the variable.

F
freeExec, 2022-03-06
@freeExec

As usual, we need a reference to the desired class instance (well, unless of course it's a static variable).
Or we drag this link in the inspector in advance. Or we look for the GameObject we need in any possible way and get the component we are interested in from it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question