Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using UnityEngine;
- public class SpawnerControl1 : MonoBehaviour
- {
- public GameObject BoxPrefab;
- public GameObject Spawner;
- public GameObject OuchModal;
- public GameObject SpawnedBox;
- [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);
- SpawnedBox = Instantiate(BoxPrefab, spawnPosition, Quaternion.identity);
- }
- public void OnClick() =>
- OuchModal.SetActive(true);
- public void OuchModal_Close()
- {
- OuchModal.SetActive(false);
- Destroy(SpawnedBox);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement