Advertisement
Guest User

xaxaxa

a guest
Jan 22nd, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class code_SpawnObjectRandom : MonoBehaviour
  6. {
  7. public GameObject spawnObject;
  8. public float xPos;
  9. public float yPosInterval;
  10. public float minTimeRange;
  11. public float maxTimeRange;
  12. private float initTime;
  13.  
  14. void Start()
  15. {
  16. initTime = Random.Range(minTimeRange, maxTimeRange);
  17. }
  18.  
  19. private void Update()
  20. {
  21. Spawn();
  22. }
  23.  
  24. public void Spawn()
  25. {
  26. initTime -= Time.deltaTime;
  27. if (initTime <= 0)
  28. {
  29. GameObject newObject = Instantiate(spawnObject);
  30. newObject.GetComponent<Transform>().position = new Vector2(xPos, Random.Range(yPosInterval, -yPosInterval));
  31. float randTimeInterval = Random.Range(minTimeRange, maxTimeRange);
  32. initTime = randTimeInterval;
  33.  
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement