Guest User

Untitled

a guest
Jul 15th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. public GameObject columnPrefab;
  2. private Vector2 objectPoolPosition = new Vector2(0,900);
  3. private float timeSinceLastSpawned;
  4. public float spawnRate = 3f;
  5. public GameObject SimpleObject;
  6.  
  7.  
  8. void Start () {
  9.  
  10. timeSinceLastSpawned = 0f;
  11. // InvokeRepeating ("InstantiateObject", 5f,2f);
  12. }
  13.  
  14. public Transform target;
  15.  
  16. public float speed;
  17. public void InstantiateObject()
  18. {
  19.  
  20. SimpleObject = (GameObject)Instantiate(columnPrefab, objectPoolPosition, Quaternion.identity);
  21. SimpleObject.transform.SetParent (GameObject.FindGameObjectWithTag("Canvas").transform, false);
  22. }
  23.  
  24.  
  25. void Update()
  26. {
  27. timeSinceLastSpawned += Time.deltaTime;
  28.  
  29. float step = speed * Time.deltaTime;
  30. if (timeSinceLastSpawned >= spawnRate) {
  31.  
  32. InstantiateObject ();
  33. SimpleObject.transform.position = Vector3.MoveTowards (SimpleObject.transform.position, target.position, step);
  34. timeSinceLastSpawned = 0f;
  35. }
  36. }
Add Comment
Please, Sign In to add comment