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 lastBlockSpawner : MonoBehaviour
- {
- public GameObject building;
- public GameObject parent;
- SpriteRenderer sr;
- Vector2 screenRes;
- Camera c;
- public float gap;
- public bool generationDone = false;
- // Start is called before the first frame update
- void Start()
- {
- sr = GetComponent<SpriteRenderer>();
- gap = Random.Range(blackboard.spawnGapRange.x, blackboard.spawnGapRange.y);
- }
- // Update is called once per frame
- void Update()
- {
- c = Camera.main;
- screenRes = c.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));
- if (transform.position.x + gap < screenRes.x && !generationDone)
- {
- generationDone = true;
- GameObject g = Instantiate(building, new Vector3(screenRes.x, 0, 0), transform.rotation);
- }
- if(transform.position.x + blackboard.blockUnitWidth < -(screenRes.x))
- {
- Destroy(parent);
- }
- }
- private void OnDrawGizmos()
- {
- Gizmos.color = Color.red;
- Gizmos.DrawSphere(new Vector3(transform.position.x + gap, transform.position.y, 0), 0.1f);
- Gizmos.color = Color.green;
- Gizmos.DrawSphere(new Vector3(transform.position.x + blackboard.blockUnitWidth, transform.position.y, 0), 0.1f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement