Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- using Random = UnityEngine.Random;
- public class BoxSpawner : MonoBehaviour
- {
- public Box BoxPrefab;
- public GameObject OuchModal;
- [SerializeField]
- private float _timeStep;
- private void Start() =>
- StartCoroutine(SpawnObjects());
- private IEnumerator SpawnObjects()
- {
- while (true)
- {
- yield return new WaitForSeconds(_timeStep);
- SpawnBox();
- }
- }
- private void SpawnBox()
- {
- float randomX = Random.Range(-2.21f, 2.21f);
- var spawnPosition = new Vector2(randomX, transform.position.y);
- Box box = Instantiate(BoxPrefab, spawnPosition, Quaternion.identity);
- box.Initialize(this);
- }
- public void OnClick() =>
- OuchModal.SetActive(true);
- public void OuchModal_Close()
- {
- OuchModal.SetActive(false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement