Spawn Objects at Random Position in Unity

Описание к видео Spawn Objects at Random Position in Unity

In this video we will learn How to Spawn Objects at Random Positions in Unity. Spawning Objects at Random Positions in our Unity Scene is very simple and it can be used to Spawn Enemies, Obstacles, Powerups etc. In the last video we learned how to spawn objects at a specific location. Link to that video    • How to Spawn Objects in Unity [Using ...  . Now let us learn to Spawn them at Random Positions. If you liked the video please like and subscribe so I can make more videos and if you have any video ideas please write them in the comment section below.


CODE USED IN THE RANDOMSPAWNER C# SCRIPT:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RandomSpawner : MonoBehaviour
{
public GameObject cubePrefab;

void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
Vector3 randomSpawnPosition = new Vector3(Random.Range(-10, 11), 5, Random.Range(-10, 11));
Instantiate(cubePrefab, randomSpawnPosition, Quaternion.identity);
}
}
}

#Unity3d #SpawnInUnity #InstantiateInUnity

Комментарии

Информация по комментариям в разработке