Forum begins after the advertisement:


[Part 7] My Maps cannot update

Home Forums Video Game Tutorial Series Creating a Metroidvania in Unity [Part 7] My Maps cannot update

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #14926
    Elvin Sim
    Participant
    public class MapManager : MonoBehaviour
    {
        [SerializeField] private GameObject mapParent; // Parent GameObject for all maps
        [SerializeField] GameObject[] maps;
    
        [Header("Zoom Settings")]
        [SerializeField] private float zoomStep = 2f;
        [SerializeField] private float minZoom = 1f;
        [SerializeField] private float maxZoom = 10f;
    
        [Header("Movement Settings")]
        [SerializeField] private float moveSpeed = 400f;
    
        Bench bench;
    
        private void OnEnable()
        {
            bench = FindObjectOfType<Bench>();
            if ( bench != null )
            {
                if(bench.interacted )
                {
                    UpdateMap();
                }
            }
        }
    
        private void Update()
        {
            HandleMapMovement();
        }
    
        public void UpdateMap()
        {
            var savedScenes = SaveData.Instance.sceneNames;
    
            for(int i = 0; i < maps.Length; i++)
            {
                if(savedScenes.Contains("The Forest of Beginnings_" + (i + 1)))
                {
                    maps[i].SetActive(true);
                }
                else if (savedScenes.Contains("The Abyssal Depths_" + (i + 1)))
                {
                    maps[i].SetActive(true);
                }
                else if (savedScenes.Contains("The Bastion of Strife_" + (i + 1)))
                {
                    maps[i].SetActive(true);
                }
                else if (savedScenes.Contains("The Ruins of Unity_" + (i + 1)))
                {
                    maps[i].SetActive(true);
                }
                else
                {
                    maps[i].SetActive(false);
                }
            }
        }
    
        public void ZoomIn()
        {
            Vector3 newScale = mapParent.transform.localScale + Vector3.one * zoomStep;
            if (newScale.x <= maxZoom && newScale.y <= maxZoom)
            {
                mapParent.transform.localScale = newScale;
            }
        }
    
        public void ZoomOut()
        {
            Vector3 newScale = mapParent.transform.localScale - Vector3.one * zoomStep;
            if (newScale.x >= minZoom && newScale.y >= minZoom)
            {
                mapParent.transform.localScale = newScale;
            }
        }
    
        private void HandleMapMovement()
        {
            Vector3 movement = Vector3.zero;
    
            if (Input.GetKey(KeyCode.L))
            {
                movement.x -= moveSpeed * Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.J))
            {
                movement.x += moveSpeed * Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.K))
            {
                movement.y += moveSpeed * Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.O))
            {
                movement.y -= moveSpeed * Time.deltaTime;
            }
    
            mapParent.transform.position += movement;
        }
    }
    #14927
    Elvin Sim
    Participant

    Only the “The Forest of Beginnings_” can updated but others scenenames cannot update

    #14928
    #14930
    #14931
    Elvin Sim
    Participant

    The name is not wrong, the order also not wrong but still cannot

    #14932
    Elvin Sim
    Participant

    thank you, I solve the problem

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Go to Login Page →


Advertisement below: