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?
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;