unity报错warning CS0618: 'Object.FindObjectOfType()' is obsolete: 'Object.FindObjectOfType has been deprecated

Assets\SampleResources\Scripts\UnityMainThreadDispatcher.cs(34,25): warning CS0618: 'Object.FindObjectOfType<T>()' is obsolete: 'Object.FindObjectOfType has been deprecated. Use Object.FindFirstObjectByType instead or if finding any instance is acceptable the faster Object.FindAnyObjectByType'

导致该问题的原因:unity版本更新

这个警告 ​CS0618​ 表明你代码中使用的 Object.FindObjectOfType<T>()方法已经被 Unity 标记为过时(Obsolete)​。自 Unity 2023.1 版本起,此方法以及 FindObjectsOfType开始被弃用,并计划在未来的版本中移除。而Unity 官方推荐使用新的方法来替代,主要原因在于性能优化。

旧的 FindObjectOfType方法在返回结果前会默认按物体的 InstanceID 进行排序,而这个排序操作消耗了该方法绝大部分的执行时间(在一些测试中甚至超过90%),但在大多数情况下这种排序并非必要。

[unity] implementation after clicking a button, delay and switch the background image/interface

There might be a better way, but so far I've found that you can do this, and you can try other ways.

 

Goal: In UNITY, after clicking a button, three screens (or Raw images) appear in sequence: the first screen appears 1 second later, the second screen appears 3 seconds later and the first screen disappears, and the third screen appears 3 seconds later and the second screen disappears. The first step is to create a C# script in Assets, let's name it delaydisplay3, double-click visual studio to open the edit.