W
W
WalVix2021-04-07 12:53:12
Unity
WalVix, 2021-04-07 12:53:12

How to make a button jump to a specific model in terrain in Unity3D?

There is canvas and panel, there are buttons on it. There is terrain with models. How can I make sure that when the button is clicked, the desired model opens? As far as I know, you do this through SetActiv or restarting the scene, but I can’t figure it out. Everything should happen in one scene so that optimization does not suffer.

The script that is currently being used (with the help of it only one model is opened, active, or if all are active, then all are called at once):

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

public class Transitions : MonoBehaviour
{
    public int scene; // Отвечает, на какую сцену переходим.

    public GameObject libraryPanel; // Библиотека(Panel).
    public GameObject menuPanel; // Главное меню(Panel).
    public GameObject terrainModel; // Трейн с моделькой.
    public GameObject buttonBack_Model;

    public int back = 0;

    private void Start()
    {
        if (PlayerPrefs.HasKey("back"))
            back = PlayerPrefs.GetInt("back");

        if (back == 1)
        {
            menuPanel.SetActive(false);
            libraryPanel.SetActive(true);
            back = 0;
        }
    }

    /* По книку загружаеться сцена */
    public void AR_Scene()
    {
        SceneManager.LoadScene(scene);
    }

    public void Library()
    {
        menuPanel.SetActive(false);
        libraryPanel.SetActive(true);
    }

    public void BackMenu()
    {
        SceneManager.LoadScene(0);
    }

    public void Model1Open()
    {
        libraryPanel.SetActive(false);
        terrainModel.SetActive(true);
        buttonBack_Model.SetActive(true);
    }

    public void BackLibrary()
    {
        back = 1;
        SceneManager.LoadScene(0);
    }

    private void Update()
    {
        PlayerPrefs.SetInt("back", back);
    }

    private void OnApplicationQuit()
    {
        PlayerPrefs.Save();
    }


}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question