Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by dualproject · Apr 06, 2016 at 10:30 AM · destroydestroy object

Destroy this game object will destroy all clone

Issue in a Simple Exercise : a red cube wil spawn: white cube
the white cube will move to the bottom, and when the distance between him and the red cube will be enought, will set a variable in the red cube "spawn.js" script so that the red cube will spawn another one. alt text Actually the project work very well! The problem is when i try to destroy a white cube.
when i use:
Destroy(this.gameObject);

All the white will be destroyed...
WHITE CUBE SCRIPT

 #pragma strict
 private var flag = 1;
 public var spawn_distance :float;
 //the targhet is my spawn point. my objective is to spawn another of this 
 //object only when this is far away from the spawn point
 public var distance_targhet : GameObject;
 function Start () {
 
 }
 
 function Update () {
 
 
     if (flag == 1 ) {
         //ill find the spawn.js actually in the "red" object that is my spawn point
         var script : spawn = FindObjectOfType(spawn);
         //this object is mooving away from the spawn so when distance is enought ill will make the spawn poit ready to spawn
         var distance = Vector3.Distance(gameObject.transform.position, distance_targhet.transform.position);
     
         if (distance > spawn_distance) {
         flag=2;
         //the dist is OK now "red" will spawn another white cube
         script.can_spawn=1;
         
         }
     }
     if (flag >= 2 ) {
        //just to try after a few update i will destroy this object.
         flag=flag+1;
         Debug.Log(flag);
         if (flag == 100 ) {
             //THERE ARE MORE THAN 10 CLONE OF THIS OBJECT SPAWNED BUT THIS DESTROY ALL OF THEM .. NOT ONLY THIS ONE ?
             Destroy(this.gameObject);
         }
     
     }    
 }


RED CUBE SCRIPT

 #pragma strict
 //im a red cube on top of the layout
 public var can_spawn = 0;
 public var continusly_spawn = 0;//if set to 1 i will spawn whithout autorization
 public var thing_to_spawn : GameObject;  //this thing to spawn is a white cube 
 //the white cube will move away from my position and will set my "can_spawn" varible when 
 //the distance between us is enought 
 
 function Start () {
 
 
 }
 
 function Update () {
 
     if( can_spawn == 1 ) { //normally is set to 0, this will be set to 1 by a white cube when distance is enought
         
     Debug.Log("OK READY TO SPAWN"); //i will spawn an object then reset 
      Instantiate(thing_to_spawn, transform.position, transform.rotation); 
     can_spawn =0+continusly_spawn;
         
         
     }
     else Debug.Log("NOT READY TO SPAWN"); 
 
 }

immm.jpg (5.8 kB)
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 knh190 · Nov 05, 2018 at 10:45 PM 0
Share

solution found?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by dualproject · Apr 06, 2016 at 05:32 PM

just up :)

Comment
Add comment · 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

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

58 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problem after 5 seconds destroy/deactivate component 1 Answer

Simple call animation then destroy? 0 Answers

Objects getting destroyed in unity test, but only sometimes in the phone app 0 Answers

How do i add blinking effect to an instantiated object ? 0 Answers

Bullet Destroy 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