Reputation: 322
First of all, Unity is totally new for me. I have a room in Unity, and in each corner of the room there is a camera:
Camera1, Camera2, Camera3, Camera4
Now I want to place the main camera randomly in one of that other camera positions (so, with the same scale, position and rotation). So in fact one random camera should be set as the main camera. Each time I start the game, a new random corner should be chosen. Also when I open the game on my phone, after building the project.
Can anyone tell me how to do this?
Upvotes: 0
Views: 1889
Reputation: 96
What i would personally do is not use 4 different cameras but use 1 camera that moves from position to position. using empty gameobjects and their Transform.position
. You can make an array
from wich you choose a random Object to set your camera position to
Upvotes: 2
Reputation: 347
First of all you should define your cameras in an array like this,
public Camera[] cameras;
Then populate the array within your inspector. Then you can toggle your currently selected main camera with some code that might look something like this:
int cameraIndex = Random.Range(0, cameras.Length); camera.Main = cameras[cameraIndex];
Upvotes: 1