Search Unity

FindObjectsOfType(Transform) confusing me

Discussion in 'Scripting' started by rennat, Mar 1, 2008.

  1. rennat


    Feb 23, 2008
    Hey I have a scene that has one gameobject with a couple of children (global lights an the main camera) but everything else is generated via the function "BuildLevel()",

    I would like to be able to get back to the previous state before I called "BuildLevel()" so that if a user changes an option or a new game starts I don't have to keep loading the same scene over and over again. I could just delete everything but the main controller and call "BuildLevel()" again.

    I attempted using "FindObjectsByType(Transform)" and filtering the results but it did not remove anything from the level. It is extremely possible that I just dont understand the data returned by "FindObjectsOfType()" or that I just don't understand Transforms very well (I tried "FindObjectsOfType(GameObject)" first)

    here is what I have that doesn't work
    Code (csharp):
    1. var old = FindObjectsOfType(Transform);
    2. for (var object : Transform in Old) {
    3.   if ( != "Level" != "MainCamera" != "Sunlight") {
    4.     Destroy(object);
    5.   }
    6. }
    any suggestions?
  2. bronxbomber92


    Nov 11, 2006
    try Destroy(object.gameObject) since the local variable is a transform.