rewt
New vMember
Posts: 2
|
Post by rewt on Dec 26, 2018 9:53:08 GMT
How to make the scene restart after death not automatically but by pressing a button
public float currentHealth
{
get
{
return _currentHealth;
}
protected set
{
_currentHealth = value;
if (!_isDead && _currentHealth <= 0)
{
//_isDead = true;
//onDead.Invoke(gameObject);
}
}
}
public bool isDead
{
get
{
if (!_isDead && currentHealth <= 0)
{
//_isDead = true;
//onDead.Invoke(gameObject);
}
return _isDead;
}
set
{
_isDead = value;
}
}
code button
public virtual void Restart()
{
Debug.Log("Restart");
_isDead = true;
Scene scene = SceneManager.GetActiveScene();
SceneManager.LoadScene(scene, LoadSceneMode.Single);
}
tried so
public virtual void Restart()
{
Debug.Log("Restart");
_isDead = true;
onDead.Invoke(gameObject);
}
|
|
|
Post by solarfalcon on Dec 26, 2018 19:45:36 GMT
After reading this, I decided to quit being lazy and implement this for my project as well.
Here is a simple way to do this. In vGameController look for OnCharacterDead and take what's in the else section and place it inside an Update with a bool like so:
private void Update()
{
if(waitForButtonPress)
{
if(Input.anyKeyDown)
{
if (displayInfoInFadeText && vHUDController.instance)
vHUDController.instance.ShowText("Restarting Scene...");
Invoke("ResetScene", respawnTimer);
}
}
}
and replace the else section inside OnCharacterDead() with
waitForButtonPress = true;
Make sure to add waitForButtonPress = false in Start() or it will continually reset the game every time you press a button.
Hope this helps.
|
|