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
- This topic has 5 replies, 1 voice, and was last updated 6 months, 1 week ago by Elvin Sim.
Viewing 6 posts - 1 through 6 (of 6 total)
-
AuthorPosts
-
June 4, 2024 at 1:05 am #14926::
<code>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; } }</code>
June 4, 2024 at 1:06 am #14927June 4, 2024 at 1:09 am #14928June 4, 2024 at 11:08 am #14930June 4, 2024 at 11:10 am #14931June 4, 2024 at 11:56 am #14932 -
AuthorPosts
Viewing 6 posts - 1 through 6 (of 6 total)
- You must be logged in to reply to this topic.
Advertisement below: