Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class GameObjectSpawner : MonoBehaviour
- {
- public GameObject coin;
- float randX;
- Vector2 whereToSpawn;
- public float spawnRate = 2f;
- float nextSpawn = 0.0f;
- void Start()
- {
- }
- void Update()
- {
- if(Time.time > nextSpawn)
- {
- nextSpawn = Time.time + spawnRate;
- randX = Random.Range (-8.4f, 8.4f);
- whereToSpawn = new Vector2(randX, transform.position.y);
- Instantiate(coin, whereToSpawn, Quaternion.identity);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement