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 SPQR · Feb 20, 2013 at 04:03 PM · gameobjectprefabdestroy

Why can't I destroy my Prefab ? Please help I'm new.

 using System.Collections;
 using System.Collections.Generic;
 
 public class FDEnviroment : MonoBehaviour {
 //Variables Start-------------------------------------------------------------------
     public enum State
     {
         Idle,
         Initialize,
         Setup,
         Spawn
     }
     
     public State state;
        public GameObject[] PlanetSpawanLocation;
     public GameObject[] PlanetObjectPrefab;
     PlayerStats MyStats;
     private int MyAccountChk;
 //Variables End----------------------------------------------------------------------_____________________________________    
     
     void Awake()
     {
         
         state = FDEnviroment.State.Initialize;
         
         //Instantiate(PlanetObject,new Vector3(-0.050f,0.15f,0.59f),Quaternion.identity);
         // this is needed only if you want to load from the assets file
         //PlanetObject = (GameObject)Resources.Load("MyPlanet", typeof(GameObject)); 
     }
     
     // Use this for initialization
     IEnumerator Start ()
     
     {
         while(true)    {
             switch(state){
             case State.Initialize:
                 Initialize();
                 break;
             case State.Setup:
                 Setup();
                 break;
             case State.Spawn:
                 Spawn();
                 break;
             }
             yield return 0;
         }
         
         
         //    Instantiate(PlanetObject,new Vector3(-0.050f,0.15f,0.59f),Quaternion.identity);
     }
         
     private void Initialize()
     {   Debug.Log(" We are in the Initialize function");
         if(!checkForPlanetPrefabs())
             return;
         if(!checkForSpawnPoints())
             return;
         state = FDEnviroment.State.Setup;        
     
     }
         
         private void Setup()
     {   Debug.Log(" We are in the setup function");
         state = FDEnviroment.State.Spawn;
         
     }
     
         private void Spawn()
     {   Debug.Log(" We are in the spawn function");
         
         GameObject[] ObjItem = AvailableSpawnPoints();
         for(int cnt = 0; cnt < ObjItem.Length; cnt++)
         {
             GameObject it = Instantiate(PlanetObjectPrefab[Random.Range(0,PlanetObjectPrefab.Length)],ObjItem[cnt].transform.position,
                                                                                 Quaternion.identity)as GameObject;
             it.transform.parent = ObjItem[cnt].transform;
         }
         
         state = FDEnviroment.State.Idle;
         
     }
     
     // check to see if we have at least one prefab t0 spawn
     private bool checkForPlanetPrefabs()
     {
         if(PlanetObjectPrefab.Length > 0)
         return true;
         else
             return false;
     }
     
     // check to see if we have at least one spawn point to spawn object
     
         private bool checkForSpawnPoints()
     {
         if(PlanetSpawanLocation.Length > 0)
             return true;
         else
             return false;
     }
     
     
     // Generate a list of available spawnpoints that do not have any objects childed to it
     private GameObject[] AvailableSpawnPoints()
     {
         List ObjItem = new List ();
         for(int cnt = 0; cnt ();
             MyAccountChk = MyStats.Account;
             if(MyAccountChk > 300)
         {
             PlanetDestroy();
         }
             
     }
 }
Comment
Add comment · Show 4
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 flaviusxvii · Feb 20, 2013 at 04:07 PM 0
Share

I've reformatted your code. Be sure to use the little "1010101" button to format your code in the future.

avatar image flaviusxvii · Feb 20, 2013 at 04:08 PM 0
Share

What error messages you get? Where is your "PlanetDestroy" function?

avatar image robertbu · Feb 20, 2013 at 04:18 PM 0
Share

So what is the problem? The only "Destroy" is this code is "PlanetDestroy()" (which you did not include the source for).

avatar image Professor Snake · Feb 20, 2013 at 04:44 PM 0
Share

Without being able to look at the code that has the Destroy function, i can only guess that you are trying to destroy the prefab itself and not an instanced version of it. Ins$$anonymous$$d of destroying PlanetObject, you should store the gameobject Instantiate returns to a variable and destroy that:

 var spawnedObject:GameObject;
 spawnedObject=Instantiate(PlanetObject,new Vector3(-0.050f,0.15f,0.59f),Quaternion.identity);
 Destroy(spawnedObject); //NOT Destroy(PlanetObject)

0 Replies

· Add your reply
  • Sort: 

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

11 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

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Trying to get bullet to collide and be destoryed 1 Answer

How many time does a prefab takes to load?? 1 Answer

Deleting a GameObject 2 Answers

Collision Detection for a Prefab 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