Hello everyone, I need help.
on visual script, how do I make my game end?
I have 3 shields(points) and when the last one is destroyed the game should end.
Please help
Thank you kindly
1 Answer
1Make an end game scene if that is what you want. Something that says for example, you lose! When the last one is destroyed, teleport to that scene by using the loadscene method.
Here is an example script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class (The script's name) : MonoBehaviour
{
[SerializeField] private string EndGame = "(The end game scene's name)";
public void EndGame()
{
SceneManager.LoadScene(EndGame);
}
void Update()
{
if (points == 0)
{
EndGame()
}
}
}
Note
Please note that if you want to use this script, you must first turn your points variable to static, which I believe is in another script. Turning a variable to static makes it accessible by other script. Example:
public static int points = 3;
Please be more specific. What do you mean by "end" the game? Simply restart the level? Show a menu? etc. The more information you give the more likely someone will try to answer your question.
– Ady_M