help me create a code in which the number of objects that appear will be counted and this will be displayed on the screen
People will help, but we aren't going to do it for you. Show what you tried and tell us what went wrong.
What was said above is true; we arent just gonna do it for you. That said, i doubt that from the description you gave anybody could even produce the result you are looking for. Which objects? Spawned through the script doing the counting? The objects spawned from other scripts? Are the spawners known or unknown? And so on and so on. There are many ways to interprete what you just said, and many different aspects where you may have problems. So as a rule of thumb, always try to be as clear as possible for what it is you want. And where you had troubles when you tried doing it yourself.
Declare a variable public int count; When an object appears, increment count by 1 ManagerScriptOrWhatever.count++; In a UI script, declare a text variable public TextMeshProUGUI countText; (make sure you assign in inspector) (also make sure you're using TMPro; Display the count in the Update() function countText.text = "Objects in scene: " + ManagerScriptOrWhatever.count.ToString();
Why would you display the count in an update function instead of just updating the text when you increment the count?
It's not very taxing to update text every frame. Since this guy is new it is the easiest to get working. I never update text in Update() but that's how I started.
What?! No, since the guy is new best not to be teaching him bad habbits. There is no point in learning something incorrectly before learning it correctly when the information is already at hand to do it right the first time. Just because you learnt to do something incorrectly first, doesnt mean thats a good way to encourage others to do it. There is never an acceptable reason to do that in update when it can be done outside of it, it doesnt matter whether it is taxing or not, its simply not good code and you would fail a code review here in industry for that, same as you would fail an assignment back at university. OP: same as others have said no-one is going to do it for you. If you need those services best to hire a developer on freelancer, upwork or unity connect https://connect.unity.com/
Code (csharp): private int objectsWhichAppeared = 0; public Text ObjectsText; public void CallWhenObjectAppears() { objectsWhichAppeared++; ObjectsText.text = objectsWhichAppeared.ToString(); }