Skip to content

Instantly share code, notes, and snippets.

@TheCuttlefish
Created March 8, 2021 13:36
Show Gist options
  • Save TheCuttlefish/5c4275edbe20d34660c861f7ae164cd3 to your computer and use it in GitHub Desktop.
Save TheCuttlefish/5c4275edbe20d34660c861f7ae164cd3 to your computer and use it in GitHub Desktop.
Saving object data (static class)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class GameStates
{
public static bool BOX_ONE_IS_ACTIVE = true;
public static bool BOX_TWO_IS_ACTIVE = true;
public static bool BOX_THREE_IS_ACTIVE = true;
public static bool BOX_FOUR_IS_ACTIVE = true;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectState : MonoBehaviour
{
bool isActivated;
[Range (0, 4)]
public int objectNum;
private void Awake()
{
if(objectNum == 0) isActivated = GameStates.BOX_ONE_IS_ACTIVE;
if (objectNum == 1) isActivated = GameStates.BOX_TWO_IS_ACTIVE;
if (objectNum == 2) isActivated = GameStates.BOX_THREE_IS_ACTIVE;
if (objectNum == 3) isActivated = GameStates.BOX_FOUR_IS_ACTIVE;
if (isActivated == false)
{
GetComponent<SpriteRenderer>().color = Color.red;
isActivated = true;
}
else
{
GetComponent<SpriteRenderer>().color = Color.white;
isActivated = false;
}
}
private void OnMouseDown()
{
if(isActivated == false)
{
GetComponent<SpriteRenderer>().color = Color.red;
isActivated = true;
if (objectNum == 0) GameStates.BOX_ONE_IS_ACTIVE = false;
if (objectNum == 1) GameStates.BOX_TWO_IS_ACTIVE = false;
if (objectNum == 2) GameStates.BOX_THREE_IS_ACTIVE = false;
if (objectNum == 3) GameStates.BOX_FOUR_IS_ACTIVE = false;
}
else
{
GetComponent<SpriteRenderer>().color = Color.white;
isActivated = false;
if (objectNum == 0) GameStates.BOX_ONE_IS_ACTIVE = true;
if (objectNum == 1) GameStates.BOX_TWO_IS_ACTIVE = true;
if (objectNum == 2) GameStates.BOX_THREE_IS_ACTIVE = true;
if (objectNum == 3) GameStates.BOX_FOUR_IS_ACTIVE = true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment