Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class GameObjectSpawner : MonoBehaviour
  6. {
  7. public GameObject coin;
  8. float randX;
  9. Vector2 whereToSpawn;
  10. public float spawnRate = 2f;
  11. float nextSpawn = 0.0f;
  12.  
  13. void Start()
  14. {
  15.  
  16. }
  17.  
  18. void Update()
  19. {
  20. if(Time.time > nextSpawn)
  21. {
  22. nextSpawn = Time.time + spawnRate;
  23. randX = Random.Range (-8.4f, 8.4f);
  24. whereToSpawn = new Vector2(randX, transform.position.y);
  25. Instantiate(coin, whereToSpawn, Quaternion.identity);
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement