1
votes

I am creating a game that shifts the player between an isometric overhead view of the map, into a perspective view. The player starts by looking at the map as such,

Isometric view of map | Scene A

Upon clicking either of the red orbs floating, the player shifts into a separate scene in the perspective view at the orb location. Shown here,

Perspective 1 | Scene B


Perspective 2 | Scene B

The isometric map and the perspective maps are different scenes and it is important that they remain as such. The player needs to be able to click on an orb in Scene A and then have the camera move to the set position of the orb in Scene B.

My current thought is that each orb could have a tag (1,2,...) and once clicked, this tag would be referenced with an if statement to position the camera in the other scene. My problem is that I don't know how to reference the tag of the clicked orb once I am in the next scene. Or how I would reset this back to normal if I return to Scene A.

Here is some code that I have started, but I am not sure if I am on the right path.

using UnityEngine;
using UnityEngine.SceneManagement;

public class TagCheck : MonoBehaviour
{
    Camera m_MainCamera;

    public string sceneName;

    int count;

    private void Start()
    {
        m_MainCamera = Camera.main;
    }


    void LoadScene()
    {
        SceneManager.LoadScene(sceneName);
        DontDestroyOnLoad(gameObject);
    }

    void OnMouseDown()
    {
        LoadScene();
        Debug.Log(count);
    }

    void OnEnable()
    {
        SceneManager.sceneLoaded += OnLevelFinishedLoading;
    }

    void OnDisable()
    {
        SceneManager.sceneLoaded -= OnLevelFinishedLoading;
    }

    void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
    {

        if (count == 1)
        {
            if (GameObject.FindWithTag("1"))
            {
                m_MainCamera.transform.position = new Vector3(5f, 1.5f, 5f);
            }

            else if (GameObject.FindWithTag("2"))
            {
                m_MainCamera.transform.position = new Vector3(-5f, 1.5f, -5f);
            }
        }

        else
        {
            Destroy(gameObject);
        }


    }

Thank you all for the help! Let me know if I need to clarify anything.

2

2 Answers

0
votes

I was able to come up with a solution to this problem. I have my scene change orbs follow me into the next scene by attaching a DontDestroyOnLoad script to them. In the next scene, there is an empty game object that continuously checks for objects with specific tags. Once found, the object tells the checker to move the camera to my desired empty parent and then reset the coordinates back to 0. Here is the checker script,

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



public class tagChecker : MonoBehaviour {

    Camera m_MainCamera;

    void Start()
    {
        m_MainCamera = Camera.main;
    }

    void TagCheck()
    {
        if (GameObject.FindWithTag("1"))
        {
            m_MainCamera.transform.SetParent(GameObject.Find("Perspective1").transform); //GameObject.Find("A").transform.parent;
            m_MainCamera.transform.localPosition = new Vector3(0f, 0f, 0f);
            m_MainCamera.transform.localRotation = Quaternion.identity;
            Destroy(GameObject.FindWithTag("1"));
        }

        else if (GameObject.FindWithTag("2"))
        {
            m_MainCamera.transform.SetParent(GameObject.Find("Perspective2").transform); //GameObject.Find("A").transform.parent;
            m_MainCamera.transform.localPosition = new Vector3(0f, 0f, 0f);
            m_MainCamera.transform.localRotation = Quaternion.identity;
            Destroy(GameObject.FindWithTag("2"));
        }

        else if (GameObject.FindWithTag("3"))
        {
            m_MainCamera.transform.SetParent(GameObject.Find("Perspective3").transform); //GameObject.Find("A").transform.parent;
            m_MainCamera.transform.localPosition = new Vector3(0f, 0f, 0f);
            m_MainCamera.transform.localRotation = Quaternion.identity;
            Destroy(GameObject.FindWithTag("3"));
        }

        else if (GameObject.FindWithTag("4"))
        {
            m_MainCamera.transform.SetParent(GameObject.Find("Perspective4").transform); //GameObject.Find("A").transform.parent;
            m_MainCamera.transform.localPosition = new Vector3(0f, 0f, 0f);
            m_MainCamera.transform.localRotation = Quaternion.identity;
            Destroy(GameObject.FindWithTag("4"));
        }
    }

    void Update()
    {
        TagCheck();
    }
}

Thanks,

0
votes

I would abstract your level data information into a JSON data file or ScriptableObject instead of placing it directly into your code.

You could also have a "TeleportTo" Vector3 field and "SceneTo" Scene field on your orb object that the code can reference.