Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

unity manager.instance

Create your own custom GameManager script

//Example
public class GameManager : MonoBehaviour
{
    public static GameManager Instance;
    public static event Action<GameState> OnGameStateChanged;
    int UserScore = 0;
    int CompScore = 0;



    private void Awake()
    {
        Instance = this;
    }

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void UpdateGameState(GameState newState) 
    {
        switch (newState)
        {
            case GameState.UserScored:
                HandleUserScored();
                break;
            case GameState.CompScored:
                HandleCompScored();
                break;
            default:
                throw new NotImplementedException($"No case block for state {newState}");
        }
        OnGameStateChanged.Invoke(newState);
    }
    
    private void HandleUserScored(){
    	UserScore++;
    }
    private void HandleCompScored(){
    	CompScore++;
    }
}

public enum GameState 
{
    UserScored,
    CompScored,
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: enable asnotracking in asp.net core at global level 
Csharp :: osk c# 
Csharp :: resize image and add watermark c# 
Csharp :: c# compare 2 binary files 
Csharp :: openiddect ef core table not creating 
Csharp :: slider script unity 
Csharp :: mouse position to canvas transform 
Csharp :: get path revit linked unload 
Csharp :: Rotate Object with keyboard 
Csharp :: .net 6 foreach only if not null 
Csharp :: how to pass object as test case in nunit c# 
Csharp :: get fixedupdate interval unity 
Csharp :: .net return context.Result without extra new objectResult 
Csharp :: binary search tree c# stackoverflow 
Csharp :: c# show hidden window wpf 
Csharp :: c# printwindow chrome 
Csharp :: serenity.is required field 
Csharp :: All and Any linq c# examlpe replace 
Csharp :: C#$ 
Csharp :: set data annotation in model c# 
Csharp :: create star rating using loop in c# 
Csharp :: unity custom editor hide values in dropdown list 
Csharp :: Read from textfile and fill in textbox 
Csharp :: how to define a static color resource in xaml wpf 
Csharp :: c# bitwise or 
Csharp :: convert array to datatable c# 
Csharp :: c# reflection 
Csharp :: string stringbuilder c# 
Csharp :: c# write line variable 
Csharp :: is c# hard to learn 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =