Advertisement
firebombgames

Untitled

Mar 10th, 2020
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class lastBlockSpawner : MonoBehaviour
  6. {
  7.     public GameObject building;
  8.     public GameObject parent;
  9.     SpriteRenderer sr;
  10.     Vector2 screenRes;
  11.     Camera c;
  12.     public float gap;
  13.     public bool generationDone = false;
  14.     // Start is called before the first frame update
  15.     void Start()
  16.     {
  17.         sr = GetComponent<SpriteRenderer>();
  18.         gap = Random.Range(blackboard.spawnGapRange.x, blackboard.spawnGapRange.y);
  19.     }
  20.  
  21.     // Update is called once per frame
  22.     void Update()
  23.     {
  24.         c = Camera.main;
  25.         screenRes = c.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0));
  26.         if (transform.position.x + gap < screenRes.x && !generationDone)
  27.         {
  28.             generationDone = true;
  29.             GameObject g = Instantiate(building, new Vector3(screenRes.x, 0, 0), transform.rotation);
  30.         }
  31.         if(transform.position.x + blackboard.blockUnitWidth < -(screenRes.x))
  32.         {
  33.             Destroy(parent);
  34.         }
  35.     }
  36.  
  37.     private void OnDrawGizmos()
  38.     {
  39.         Gizmos.color = Color.red;
  40.         Gizmos.DrawSphere(new Vector3(transform.position.x + gap, transform.position.y, 0), 0.1f);
  41.         Gizmos.color = Color.green;
  42.         Gizmos.DrawSphere(new Vector3(transform.position.x + blackboard.blockUnitWidth, transform.position.y, 0), 0.1f);
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement