Advertisement
kadyr

ffgdfgfg

Jul 17th, 2021
902
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Spawner : MonoBehaviour
  6. {
  7.     [SerializeField] private GameObject crystal;
  8.     [SerializeField] private float radius = 6f;
  9.     float timer = 0f;
  10.     float coolDown = 1f;
  11.  
  12.     void Start()
  13.     {
  14.  
  15.     }
  16.  
  17.     void Update()
  18.     {
  19.         timer += Time.deltaTime;
  20.         if (timer >= coolDown)
  21.         {
  22.             float x = Random.Range(-radius, radius);
  23.             float z = Random.Range(-radius, radius);
  24.             Vector3 randomPosition = new Vector3(transform.position.x + x, 0, transform.position.z + z);
  25.             Instantiate(crystal, randomPosition, Quaternion.identity);
  26.             timer = 0;
  27.         }
  28.     }
  29.     private void OnTriggerEnter(Collider other)
  30.     {
  31.         if(other.gameObject.tag == "Crystal")
  32.         {
  33.             Destroy(other);
  34.             float x = Random.Range(-radius, radius);
  35.             float z = Random.Range(-radius, radius);
  36.             Vector3 randomPosition = new Vector3(transform.position.x + x, 0, transform.position.z + z);
  37.             Instantiate(crystal, randomPosition, Quaternion.identity);
  38.         }
  39.     }
  40. }
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement