- Home /
Instantiated object script properties
I am making a RTS game where you build armies, and bases. Then go and destroy your enemies base/army. But I have ran into another problem. When your player is created their waypoint is set to the same waypoint as the building. How do I do this? I have seen how you can instantiate a script with properties, but I need to instantiate an object, and set their scripts properties.
Answer by rutter · Apr 05, 2012 at 06:43 PM
`Instantiate()` returns a reference to the instantiated object. You can use `GetComponent()` and similar functions to find its components. From there, the particular configuration tasks will depend on what exactly you want to do.
You can see a few examples of this in Unity's manual page for instantiate calls. The page in question especially relates to instantiating prefabs, but the concepts are very similar when cloning objects in general.
It took me about ten $$anonymous$$utes to understand it, but I finally figured it out. If anyone wants to see how I did it here is my script:
OBJECTCONTROLS newtrooper;
newtrooper = Instantiate (TROOPERPREFAB, waypoint.transform.position, selected_unit_transform.rotation) as OBJECTCONTROLS;
newtrooper.$$anonymous$$YWAYPOINT.transform.position = waypoint.transform.position;
Your answer
Follow this Question
Related Questions
Call instantiated object from other script. 1 Answer
How do I check a variable of an instantiated object from another instantiated object? 1 Answer
Screen go darker when it look at an Object? 1 Answer
How do you create a "collect" objection that corresponds with the enemy behavior in C#? 1 Answer
getting the object that the running script is attached to 1 Answer