Guest User

Untitled

a guest
Nov 19th, 2022
410
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class SpawnerZone : MonoBehaviour
  4. {
  5.     public GameObject cubePrefab;
  6.     public Vector3 size;
  7.  
  8.     void Update()
  9.     {
  10.         if(Input.GetKeyDown(KeyCode.Space))
  11.         {
  12.             GameObject instantiated = GameObject.Instantiate(cubePrefab);
  13.             instantiated.transform.position = new Vector3(
  14.                 Random.Range(transform.position.x - size.x / 2, transform.position.x + size.x / 2),
  15.                 Random.Range(transform.position.y - size.y / 2, transform.position.y + size.y / 2),
  16.                 Random.Range(transform.position.z - size.z / 2, transform.position.z + size.z / 2)
  17.                 );
  18.         }
  19.     }
  20.  
  21.     private void OnDrawGizmos()
  22.     {
  23.         Gizmos.color = Color.red;
  24.         Gizmos.DrawWireCube(transform.position, size);
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment