简体   繁体   中英

Start scene from certain point in unity?

I am quite new in game development, I am using Unity in combination with C# with Models which are made in Blender.

I was wondering, if there is a way to "play" a scene from a certain point. For example, if I have a game (single scene for simplicity now) and like to test a certain part of the Game (eg I would like to test the 3rd of 5th quests within this scene, assuming that you can access the 2nd quest only if you successfully completed the 1st one, and so on).

But I really don't wanna to play through my scene for a while, just to reach the point which I originally wanted to test.

How can i achieve this? And if it is not possible in some simple way, is there some kind of workaround for this?

Thanks!

Not sure if I understood correctly, but if you want to jump from scene to scene, within your project, you can always use the sceneManager.

https://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html

Hope that helps.

In your class, create a variable that holds the value for starting quest. eg 3.

Then for testing purpose, in the Start() method, you can check the value of that variable and write some code to change the elements in the scene to represent the corresponding quest(3 in this case) like the position of the character, or next objective or anything that is specific to the quest.

You can make this variable public so that you can change its value from unity instead of opening the script every time.

I am not sure if it is feasible for your game, but if you have a lot of things that change for each quest, it is best to have a different scene for each one of them.

Here is the sample code on how i did it.. hope this will help you.. Create a C# script called GoScene1

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GoScene1 : MonoBehaviour {
    public void Scene1Change() {
        Application.LoadLevel("GoScene1");
    }
}

Then Create a C# Script Called GoScene2

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GoScene2 : MonoBehaviour {
    public void Scene2Change() {
        Application.LoadLevel("GoScene2");
    }
}

Heres the Screen shot... 在此处输入图片说明 在此处输入图片说明

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM