A
A
AlexGenesis2021-11-05 22:33:21
C++ / C#
AlexGenesis, 2021-11-05 22:33:21

How to store GetComponent in a variable?

Hello, I have the following code:

void Start()
{
     SomeType SomeName = gameObject.GetComponent<RectTransform>().anchoredPosition;
     
     SomeName = new Vector2(x, y);
}


How can I implement such a code so that I can save some value of an object into a variable without breaking the connection with the object itself, and in the future access this variable in order to directly change the value of the object itself.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-11-05
@AlexGenesis

Save not anchoredPosition to variable, but RectTransform itself

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question