Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity singleton

public class example : MonoBehaviour 
{
    public static example my_object { get; private set; } ;

    float my_player_health=100;

     private void Awake()
    {
        if (my_object != null && my_object != this)
        {
            Destroy(this);
        } else {
            my_object = this;
        }
       DontDestroyOnLoad(this.gameObject);
    }
}
Source by vionixstudio.com #
 
PREVIOUS NEXT
Tagged: #unity #singleton
ADD COMMENT
Topic
Name
8+7 =