void Start() { gameObjects.Add(prefab); if (gameObjects.Contains(prefab)) { print("this item is in the list :)))))"); } gameObjects.Clear(); if (gameObjects.Contains(prefab2)) { print("this is a different item in the list now"); } /* * for (int i = 0; i < spawnAmount; i++) * { * GameObject clone = Instantiate(prefab); * Vector3 randomPos = transform.position + Random.insideUnitSphere * spawnRadius; * clone.transform.position = randomPos; * gameObjects[0] = new GameObject(); * * } */ }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Return)) { gameObjects.Clear(); Debug.Log(gameObjects.amount); } if (Input.GetKeyDown(KeyCode.Tab)) { gameObjects.AddRange(GameObject.FindGameObjectsWithTag("Ball")); Debug.Log(gameObjects.amount); } }
// Update is called once per frame void Update() { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Input.GetMouseButtonDown(0)) { if (Physics.Raycast(ray, out hit)) { Transform objectHit = hit.transform; //print(objectHit.name + " removed from list."); for (int i = 0; i < gameObjects.amount; i++) { print(gameObjects[i].name); } print(gameObjects.Contains(objectHit.gameObject)); gameObjects.Clear(); } } }