I am looking for advice how to manage a time issue. Here’s a backgound on the project: we are using our “game” in a neuroscience experiment and I have constructed three scenes. We need to be able to create a continuous program that the “player” will see:
scene A (30 seconds)
scene B (60 seconds)
scene A (30 seconds)
scene C (60 seconds)
scene A (30 seconds)
scene B (60 seconds)
scene A (30 seconds)
What is the best way to do this? I am not sure if I should use realtimeSinceStartup or…?
Thanks in advance for any help. I tried the documentation and searches but didn’t find what I was looking for. I’m a neuroscientist and not a programmer so I apologize if the answer is painfully obvious…
Depends - do you want each scene to run for 30 seconds, or the scenes to switch every thirty seconds (just imagine a 10-second load time to see my point).
I’m assuming you would like to have each scene run for 30 seconds. In the case I’d put a script like this on a game object in each level.
var nextLevel = 1;
// Pause this script for 30 seconds.
yield WaitForSeconds (30);
Application.LoadLevel (nextLevel)
You could use a script like this, and put that on an empty GameObject in Scene 0, then put your Scene A, Scene B, and Scene C to take up scene indexes 1-3. Then be sure to rename the variables in the inspector to what your scenes are called.
// Put this script on an empty GameObject in a scene and make that scene be index 0 in your build settings.
var sceneAName = "Scene A Name";
var sceneBName = "Scene B Name";
var sceneCName = "Scene C Name";
function Start()
{
// This is key to make sure this script keeps running between scenes
DontDestroyOnLoad(gameObject);
while (true) // loop through the scenes indefinitely
{
Application.LoadLevel(sceneAName); // load a scene
yield WaitForSeconds(30); // wait around while the scene does its thing for 30 seconds
Application.LoadLevel(sceneBName); // load another, etc.
yield WaitForSeconds(60);
Application.LoadLevel(sceneAName);
yield WaitForSeconds(30);
Application.LoadLevel(sceneCName);
yield WaitForSeconds(60);
Application.LoadLevel(sceneAName);
yield WaitForSeconds(30);
Application.LoadLevel(sceneBName);
yield WaitForSeconds(60);
}
}
Thanks for the replies! Actually, let me be more specific. The 30 sec “scene” is just a static picture and scene B and C are environments the “players” navigate with a joystick. So far we have just been switching monitor input to the VR goggles manually, and that gives us enough time to load the new scene while the player is looking at a static image (projected by a different computer). However, the timing is slightly different for each person since we switch things manually. I wanted to string the scenes together in one “game” so the timing would be more precise but I forgot about the load time. So is there a way to display a static image for 30 sec while loading scene B, so it is ready at real time 0:30, play that scene for 60 seconds, then look at a static image for real life time 1:30-2:00 while loading scene B, etc…?
to throw out another idea, depending on how complex your scenes are… just put them all in different areas of one scene - farther apart than your camera culling is set - and move the camera/player after yield wait for seconds. you can script a fadein/out with a solid guitexture to cover the transition (or just let it pop). enable/disable control etc. zero load time. anyway, sounds pretty interesting!
[edit: duh… you’d really only have 2 areas and your static image would be the guitexture covering the transition… If the scenes aren’t that heavy, this would be pretty easy!]
Pete, that sounds like the easiest solution yet. The two scenes are actually an enclosed maze with floor, wall, and ceilings, so the other maze would not be viewable to the camera inside the maze. I modeled the maze on the marble tutorial so the player is a sphere with a FPSWalker script and a camera. So I think I can put both mazes in the same scene, and just transfer the camera between a transition screen, the FPSWalker marble in maze B, and the FPSWalker marble in maze C.
Does just moving the camera transfer movement control to the other marble? And to transfer camera and movement control according to real-life timing, should I use that realtimeSinceStartup function?
Simply transferring the camera will not effect control. What you should do is keep a script that does SetActveRecursively() on the parent objects of each player setup depending on the current “scene”.
what yog said unless you can get away with one marble. then just move it. i don’t know the best answer for the real time q but i’ve done something similar in the past. if i can find a few minutes to dig it up i’ll put together a sample of how i’d do it. sorry - a bit busy atm though…
Thanks, I’d really appreciate an example how to manage the time issue if you are able to find it! I will see if I can figure out how to move the marble.
here you go. you should be able to swap out your geo for the Mazes and FPS controller. Move the start positions where you want them and reassign the target objects in the scripts on the controller and static image objects (and player controls of course). there’s some drift in the fade in that i didn’t have time to figure out. seems to be ok at a fadeTime value of 0.3 (set it to 1.0 and you’ll see what i mean).
Thanks, that was so helpful! I’m almost there…two questions/issues:
When I “play” the game, the static image does not display. (It just shows a black screen.) I have tried images that are multiples of 2 on each side and ones that are not, ones that are in color and ones that are not - the included picture in the example below is similar to what I want in the finished project. Why does it work on yours and not on mine?
The movement of the marble player works perfectly now. Thanks for the great script! However, I need to compile two “games” that have a finite, set order:
I understand how to manipulate the time the player remains at each location with the script (and by entering new values for the variables in the Unity GUI) but I tried to modify the script to put the moves in the correct order and then end the game and was not successful. Any hints/examples for this task?
pixel insets are all set at zero. min and max values should be - and + one half of your intended image dimensions (in this case your playback resolution since you can control it). you can make your image proportional to the final resolution so that you can use a smaller image and scale it through the pixels inset values. make it to size if you need it precise (ie the dot will scale).
in the start function of the mover script, change moveTo = 1 to moveTo = 2. this will change the initial start target. you’ll have to edit the script between builds.
to control the end game, i’d probably just increment a variable with each move. in update put the coroutine in an if statement - if i < 5 start the coroutine. the rest depends on how you want it to end.
ps… just realized there are two target vars for the player object in the mover script. that’s me being lazy and not cleaning up after making changes! sorry bout that. probably should be just one but really doesn’t matter for this - just an extra step in editor.
took a quick look and must be something other than what i wrote above (but i still say do that). might be something with the camera set up. don’t have time atm to work on it though…
after a quick look, the black screen is indeed the camera set up. well more accurately, your camera is set up as a component of the player but one of the scripts sets player.active = false during the static image so they can’t move until the next maze is up. using a camera object as a child of the player fixes this. however, on deleting the original camera component, it looks like the guitexture loses it’s positioning reference and needs to be rebuilt after you put in the new camera. haven’t had time on the rest. hope it helps and you’re making headway.
Thanks for the comment, I will try to use it as a guide when I go back to the project to try to fix the problems. I have been dealing with other issues in the experiment at the moment, but will work on the game again this weekend. I’ll be back on Monday with results, hopefully to say it’s worked out, or else with questions. As always, thanks for your input!