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 Makiavel · Oct 26, 2012 at 08:22 PM · collisiondestroyintersect

Two objects are placed at the same place. How to destroy one and keep another?

I am sorry to ask a question without even a draft of a script, but...

If I have two prefabs placed roughly at the same point, so parts of them intersect, how can I always destroy object a and keep object b? Probably I should use the collisions or something like that, but I just can't figure out the exact algorithm. It is not a bug, but a free generating space, so I have problems controlling what appears where, so I am trying to find/make a script to prevent these cases.

This is the script I use to spawn objects. I just use it again, changing the z value to have +10 always.

 var Xvalue:float = 0.0;
 var Zvalue:float = 0.0;
 var ChangeCounter:int = 1.0;
 var ChangeAmount:float = 20.0;
 var Technical_Couter:int = 1.0;
 var PlayFieldSize:float = 0.0;
 var prefab1:Transform;
 
 
 
 function Update () 
 {
     if(ChangeCounter<PlayFieldSize)
        {
        Xvalue=(ChangeAmount*ChangeCounter);
        Instantiate (prefab1, Vector3(Xvalue, 0.0, 0.0), Quaternion.identity);
 
 
     if(ChangeCounter>0)
     {
        while(Technical_Couter<(ChangeCounter+1))
          {
          Zvalue=(ChangeAmount*Technical_Couter);
          Instantiate (prefab1, Vector3(Xvalue, 0.0, Zvalue), Quaternion.identity);
          Technical_Couter++;
          }
 
        while(Xvalue>0)
        {
          Xvalue=(Xvalue-ChangeAmount);
          Instantiate (prefab1, Vector3(Xvalue, 0.0, Zvalue), Quaternion.identity);
        }
     }
        ChangeCounter++;
        Technical_Couter=1.0;
        }
 }


Also, the spawned prefab in its turn spawns one of a few prefabs at its place.

So I need to check, if the prefab at the bottom layer is too high, and collides with a prefab at the top layer, and if so, destroy the one on the top.

Comment
Add comment · Show 1
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 DaveA · Oct 26, 2012 at 08:24 PM 0
Share

Posting some code would help

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DaveA · Oct 26, 2012 at 08:26 PM

I'm guessing you generate objects by doing something like this:

 Instantiate (someObject, somePosition, someRotation);

and then don't keep track of that new object.

Keep track of it.

You could use a List for example:

 var objList : List = new List();
 
 var newGO = Intantiate (someObject.... 
 objList.Push (newGO);


or something like that. Then you can look for objects using the objList list.

Comment
Add comment · Show 1 · 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 Makiavel · Oct 26, 2012 at 08:45 PM 0
Share

So, would it be possible to check if the prefab at the bottom layer is too high, and collides with the one on top, and destroy the top one using this list?

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Destroy Turret with machine Gun 0 Answers

Destroy object when hit by other object 1 Answer

How to Destroy a gameobject on collision 3 Answers

[SIMPLE] Not loose speed when destroying colliding object 1 Answer

Destroy object after 5 collisions 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