x


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! :)

more ▼

asked Mar 27 '12 at 02:44 PM

SlyRipper gravatar image

SlyRipper
0 1 1

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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) 
    ... 
more ▼

answered Mar 27 '12 at 03:12 PM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

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 instead.

thanks for reply :)

Mar 27 '12 at 07:24 PM SlyRipper

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?

Mar 29 '12 at 10:41 AM SlyRipper
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3328
x2086
x1255
x764
x13

asked: Mar 27 '12 at 02:44 PM

Seen: 457 times

Last Updated: Mar 29 '12 at 10:41 AM