Hey guys! Me and a couple friends are working on a game where you are able to switch between 2 different game scenes for a short period of time. We want you to be able to press “Q” and switch into a different, and after 10 seconds return back to the original scene using a coroutine. Also, if it’s possible, is there any way that if the different scenes are built the game with the same coordinates, that you could put the player in the exact coordinates they left off in the other scene when they switch back. Here is my code.
///
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class WARP : MonoBehaviour
{
// Start is called before the first frame update
// Update is called once per frame
void Update()
{
Only one place to start with that! To help gain more insight into your problem, I recommend liberally sprinkling Debug.Log() statements through your code to display information in realtime.
Doing this should help you answer these types of questions:
is this code even running? which parts are running? how often does it run?
what are the values of the variables involved? Are they initialized?
Knowing this information will help you reason about the behavior you are seeing.
Use GetKeyDown(), GetKey() fires repeatedly. Though not sure in this case if it’s switching scenes…
Are both scenes in the Build settings?
To remember position, use a static Vector3 to store the player position, and update it right before switching to the next scene. Will take some fiddling to reload it etc.