Forum begins after the advertisement:
[Part 7] My Respawn button isnt working
Home › Forums › Video Game Tutorial Series › Creating a Metroidvania in Unity › [Part 7] My Respawn button isnt working
- This topic has 21 replies, 4 voices, and was last updated 6 months, 2 weeks ago by Alex.
-
AuthorPosts
-
March 23, 2024 at 12:16 pm #13611::
when playercharacter dies and when i press the respawn button nothing happens(the button doesn’t even look like its clicking). And the button has been set to interactable.
My “bench” code:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Coffin : MonoBehaviour { public bool interacted; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } private void OnTriggerStay2D(Collider2D _collision) { if(_collision.CompareTag("Player") && Input.GetButtonDown("Interact")){ interacted = true; } } }
my UIManager code:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class Coffin : MonoBehaviour { public bool interacted; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } private void OnTriggerStay2D(Collider2D _collision) { if(_collision.CompareTag("Player") && Input.GetButtonDown("Interact")){ interacted = true; } } }
My gamemanager code:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class GameManager : MonoBehaviour { public string transitionedFromScene; public Vector2 platformingRespawnPoint; public Vector2 respawnPoint; [SerializeField] Coffin coffin; public static GameManager Instance { get; private set; } private void Awake() { if(Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } DontDestroyOnLoad(gameObject); coffin = FindObjectOfType
(); } public void RespawnPlayer(){ Debug.Log("Respawned"); if(coffin != null){ if(coffin.interacted){ respawnPoint = coffin.transform.position; } else{ respawnPoint = platformingRespawnPoint; } } else{ respawnPoint = platformingRespawnPoint; } PlayerController.Instance.transform.position = respawnPoint; StartCoroutine(UIManager.Instance.DeactivateDeathScreen()); PlayerController.Instance.Respawned(); } } March 23, 2024 at 2:19 pm #13612::Update: put a event system on the canvas with stand alone input module and now, when i click button the game pauses and gives me the error “Coroutine couldn’t be started because the the game object ‘Game Manager’ is inactive!”
March 23, 2024 at 5:47 pm #13614::Hi Anuk, for the respawn button, have a read of this post and see if it helps fix your issue. It is related to the save issue with benches noted in this topic: https://blog.terresquall.com/community/topic/part-7-scenefader-nullreferenceexception-and-savedata-endofstreamexception/
Update: put a event system on the canvas with stand alone input module and now, when i click button the game pauses and gives me the error “Coroutine couldn’t be started because the the game object ‘Game Manager’ is inactive!”
For this issue, you will need to check your Hierarchy and see if the Game Manager object is inactive. If it is, what in your code is turning it inactive when the game is running?
March 25, 2024 at 1:45 pm #13630::ok, now respawning kind of works for the rooms that dont have a bench. which means i respawn at the start point of the scene i died instead of the bench on a separate scene.
also after respawning, why are my heartfills invisible? only after i get hit once my heart containers become visible again.
March 26, 2024 at 4:27 pm #13633::also after respawning, why are my heartfills invisible? only after i get hit once my heart containers become visible again.
Check your
heartContainers
to see if you assigned the parent GameObject to one of the items.March 29, 2024 at 3:58 pm #13643::i went further into the save system video and now my character respawns at the bench if he dies in another scene, but doesnt respawn(respawn button unresponsive) if he dies in the scene where the bench is.
another problem is that my cave_1 map is visible after starting the game as intended but after i interact with a bench in cave_4, instead of updating the scenes i came across, the map becomes invisible
here’s the code for bench/coffin:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Coffin : MonoBehaviour { public bool interacted; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { } private void OnTriggerStay2D(Collider2D _collision) { if(_collision.CompareTag("Player") && Input.GetButtonDown("Interact")){ interacted = true; SaveData.Instance.coffinSceneName = SceneManager.GetActiveScene().name; SaveData.Instance.coffinpos = new Vector2(gameObject.transform.position.x,gameObject.transform.position.y); SaveData.Instance.SaveCoffin(); } } private void OnTriggerExit2D(Collider2D _collision) { if(_collision.CompareTag("Player")){ interacted = false; } } }
Map Manager cade:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class MapManager : MonoBehaviour { // Start is called before the first frame update [SerializeField] GameObject[] maps; Coffin coffin; private void OnEnable() { coffin = FindObjectOfType<Coffin>(); if(coffin != null){ if(coffin.interacted){ UpdateMap(); } } } void UpdateMap(){ var savedScenes = SaveData.Instance.sceneNames; for(int i=0;i<maps.Length;i++){ if(savedScenes.Contains("Cave_"+i+1)){ maps[i].SetActive(true); } else{ maps[i].SetActive(false); } } } }
March 29, 2024 at 5:06 pm #13646::i went further into the save system video and now my character respawns at the bench if he dies in another scene, but doesnt respawn(respawn button unresponsive) if he dies in the scene where the bench is.
When you mouse over the button, does it get highlighted?
another problem is that my cave_1 map is visible after starting the game as intended but after i interact with a bench in cave_4, instead of updating the scenes i came across, the map becomes invisible
When the map becomes invisible, do they still exist in the Hierarchy?
March 30, 2024 at 2:25 pm #13650::no, if i die in the room with the bench the respawn button doesn’t get highlighted
When the map becomes invisible, they exist in the Hierarchy. but they are turned off
March 30, 2024 at 3:45 pm #13651::no, if i die in the room with the bench the respawn button doesn’t get highlighted
The respawn button may be blocked by another element in your scene. Can you try moving the button up so it becomes the first element under its parent?
When the map becomes invisible, they exist in the Hierarchy. but they are turned off
For this, can you check whether the scenes you have for the maps match the names of the GameObjects in your Map Manager component?
March 31, 2024 at 2:54 pm #13654March 31, 2024 at 3:50 pm #13655::the names of the scenes are correct and are in correct order
Move the Death Screen above the Scene Fader and see if it fixes the Respawn button not responding.
April 1, 2024 at 12:28 pm #13669::I tried and that doesn’t seem to be the problem. when I move death screen above scene fader and play the scene fader sits on top of the death screen and I cant click the button. the respawn button works if I die in another scene. I cant interact with it only if I die in the scene with the bench in it.
April 1, 2024 at 12:28 pm #13670April 1, 2024 at 4:08 pm #13674::Can you show me your Hierarchy when the Respawn doesn’t work? Record something like the above.
April 2, 2024 at 3:09 pm #13694::The Hierarchy’s dont look any different when i die in each scene.
also in the video my heartfills are invisible after reaspawn. how do i fix that
-
AuthorPosts
- You must be logged in to reply to this topic.
Advertisement below: