Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by SlyRipper · Mar 27, 2012 at 02:44 PM · gameobjectprefabdestroyinitiate

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

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) 
     ... 
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image SlyRipper · Mar 27, 2012 at 07:24 PM 0
Share

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

avatar image SlyRipper · Mar 29, 2012 at 10:41 AM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

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

Destroying a prefab on collision with a cube? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges