- Home /
How to order newly created Objects?
Hello all,
I've searched the web for help, but haven't found any suitable or at least I haven't understood it ^^
I've created a script that orders an Object (e.g. a Cube) to Position A and then B. This works well, with a pre-placed Object, because I can attach the Script to it and then set the Positons A and B with the Inspector.
My Problem now is, that his isn't working with Prefab. I've drag&dropped this Cube into a newly created Prefab and initiated it to my Scene. This works well and it pops out of nowhere.. the problem is, that Prefab won't apply my settings to it, instead there is just "None" as comment and I can't edit it there.. My newly created/initiated Cubes are just laying on the ground, doing nothing.. instead of moving to A and B.. What's wrong?
Another Question is, how can I remove this Cube when it reaches B? I've used a Collider and the Destroy() Command but it doesn't work. I guess I have wrong settings there or syntaxes. Any help would be cool.
Thanks in advance! :)
Answer by Statement · Mar 27, 2012 at 03:12 PM
Prefabs can't remember references to objects in the scene. When you instantiate them, you need to find the waypoint and assign it to them. You can destroy the object when you are within a certain radius, or right on the spot.
if (Vector3.Distance(transform.position, B.position) < 0.1f)
...
How can I assign those waypoints maually, since the Prefabs don't save them? I'm new to this and still learning also the mass of commands and syntaxes. I first thought about the addcomponent parts?
I will try the range/distance part.. But I thought the colliders would suit something like this, like the unit enters the collider and gets removed, but if this won't work I guess I'll use the check range part ins$$anonymous$$d.
thanks for reply :)
The Collider now works, but I still don't know how to add those waypoints to the Script.
I'm setting up the number of Waypoints in the inspector and get x spaces to drag&drop those waypoints (null gameObjects) into that fields.. but how can I manually add those into the script?
Your answer
Follow this Question
Related Questions
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Acessing scripts in other game objects with prefabs, without using GameObject.Find 1 Answer
Assign a 'Transform' target to prefab by finding a 'GameObject' 1 Answer
PlayerRespawn class wont Instantiate the player prefab 1 Answer