Quantcast
Channel: Questions in topic: "random spawn"
Viewing all articles
Browse latest Browse all 125

Spawn Prefab at one of 5 location cubes

$
0
0
Hey guys, I have a issue. Im making a game where the escape pod is the ending and I have 5 cubes on the map placed around, I need it so one of those 5 cubes will spawn a prefab which will be the ending, so for now a cube. And every time the scene resets or loads again then it exit will change to another random cube which was placed on the game, so the ending is random well it varys from 1 of 5 locations. here is a script I have which makes a object spawn 1 of 5 prefabs but it causes issue of making it so more then 1 cube will have the ending pod. hope this makes séance :) #pragma strict var hasWeapon : boolean = false; var weaponNumber : int; var weaponSpawner : Transform; // Place where weapons spawn var Exit1 : GameObject; // Weapon type = 1 var Exit2 : GameObject; // Weapon type = 2 var Exit3: GameObject; // Weapon type = 3 var Exit4 : GameObject; // Weapon type = 4 var Exit5 : GameObject; // Weapon type = 5 function Start() { weaponNumber = Random.Range(1,5); SpawnWeapon(); } function SpawnWeapon () { if(weaponNumber == 1) { Instantiate(Exit1, weaponSpawner.position, weaponSpawner.rotation); hasWeapon = true; } else if(weaponNumber == 2) { Instantiate(Exit2, weaponSpawner.position, weaponSpawner.rotation); hasWeapon = true; } else if(weaponNumber == 3) { Instantiate(Exit3, weaponSpawner.position, weaponSpawner.rotation); hasWeapon = true; } else if(weaponNumber == 4) { Instantiate(Exit4, weaponSpawner.position, weaponSpawner.rotation); hasWeapon = true; } else if(weaponNumber == 5) { Instantiate(Exit5, weaponSpawner.position, weaponSpawner.rotation); hasWeapon = true; } }

Viewing all articles
Browse latest Browse all 125

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>