Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public GameObject columnPrefab;
- private Vector2 objectPoolPosition = new Vector2(0,900);
- private float timeSinceLastSpawned;
- public float spawnRate = 3f;
- public GameObject SimpleObject;
- void Start () {
- timeSinceLastSpawned = 0f;
- // InvokeRepeating ("InstantiateObject", 5f,2f);
- }
- public Transform target;
- public float speed;
- public void InstantiateObject()
- {
- SimpleObject = (GameObject)Instantiate(columnPrefab, objectPoolPosition, Quaternion.identity);
- SimpleObject.transform.SetParent (GameObject.FindGameObjectWithTag("Canvas").transform, false);
- }
- void Update()
- {
- timeSinceLastSpawned += Time.deltaTime;
- float step = speed * Time.deltaTime;
- if (timeSinceLastSpawned >= spawnRate) {
- InstantiateObject ();
- SimpleObject.transform.position = Vector3.MoveTowards (SimpleObject.transform.position, target.position, step);
- timeSinceLastSpawned = 0f;
- }
- }
Add Comment
Please, Sign In to add comment