- Home /
How to randomly pick a gameobject except for one gameobject in an array ?
I have 4 player game objects in an array (players[]) in which one player is the current player. I want to randomly pick a player except for the current player. Help me out.
Answer by Casiell · Oct 29, 2018 at 10:49 AM
Linq captain here!
var nonCurrentPlayers = players.Where(player => !player.IsCurrent);
Random random = new Random();
var randomPlayer = nonCurrentPlayers[random.Next(0,nonCurrentPlayers.Count )];
@Casiell thanks for the reply... can you please convert this to c sharp script?
But, it is a C# code. "Where" is part of System.Linq namespace.
Which parts do you have problems with?
Your answer
Follow this Question
Related Questions
Instantiate randomly from array 1 Answer
What is the best way to instatiate an array of connected GameObjects? 0 Answers
Transport unknown amout of objects with GameObject array 0 Answers
View an array of the transform position/rotation of all game objects with a specified tag., 0 Answers
How to remove a gameobject from an array 2 Answers