- Home /
How to assign a private transform of my player in script?
I have a variable called "Player" and it is of type Transform. I am trying to figure out how to assign it. As seen in the picture below, I can easily assign it by just making it public and dragging the object into the public variable slot in the inspector. But I want to assign the variable using the script it is in and make it private. How do I do that?
capture.png
(4.7 kB)
Comment
Answer by Vicarian · Jun 24, 2018 at 04:31 AM
You may use a tag along with GameObject.FindWithTag(string) to locate the object and get its transform property.
if (GameObject.FindWithTag("Player"))
player = GameObject.FindWithTag("Player").transform;