I need to find all objects that have the ‘Stage’ script.
Below is the code:
public void stageSelectButton() {
var stageList = FindObjectsOfType<Stage>(); //Get all objects with the 'Stage' script in this Scene.
foreach (var stage in stageList) {
if (stage.stageSelected) { //Check if it is the selected stage
stage.OpenStage(); //Open the stage, if it is available
}
}
}
The problem is that ‘FindObjectsOfType’ is obsolete, asking to change it to ‘FindFirstObjectByType’, and I’m getting an error:
Assets\scripts\controllers\GCStageSelect.cs(17,28): warning CS0618: ‘Object.FindObjectsOfType()’ is obsolete: ‘Object.FindObjectsOfType has been deprecated. Use Object.FindObjectsByType instead which lets you decide whether you need the results sorted or not. FindObjectsOfType sorts the results by InstanceID but if you do not need this using FindObjectSortMode.None is considerably faster.’
How do I get all objects that have the ‘Stage’ script with the stageList variable?
I could define all these objects with the tag ‘Stage’, for example, and use 'GameObject.FindGameObjectsWithTag(“Stage”) to get them, but to not define tags and directly search for the objects that have the script ‘Stage’, how do I write it correctly?