This is my coin spawner script, however, there are too many coins are spawned at the same time so I want to add a random timer to keep coins from spawning too much.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Coinscript : MonoBehaviour
{
public GameObject coin;
// Update is called once per frame
void Update()
{
Vector3 randompos = new Vector3(Random.Range(3, 5.45f), -0.9455643f, 60);
Instantiate(coin, randompos, Quaternion.identity);
}
}
This is the script that is responsible for spawning coins. (3 to 5.45 is the coordination x where the coins should be spawned.)
Hurry off to tutorials for this stuff because it is never just code. There will always be scene setup components that are critical too.
Two steps to tutorials and / or example code:
do them perfectly, to the letter (zero typos, including punctuation and capitalization)
stop and understand each step to understand what is going on.
If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.
Try to think “generically”. You don’t need a coin spawner exactly you need something to occur at a random interval at a somewhat random position. Write such a method logging when it happened and at what position. A) You will be assured that your code works (without visually watching for coins) and b) you will have a method that can be reused. And c) you can modify the conditions without affecting much else.