Switch Task C# version
- Keshav Batra
- Feb 4, 2021
- 1 min read
This is gonna be my last Among Us based lesson that I will be doing. I used the same process that I had previously used in my Bolt project. The only difference is that it's actually more concise and the pieces are in the right places. Below is the coding I used to construct this and the end result.
public class Switch : MonoBehaviour
{
public GameObject up;
public GameObject on;
public bool isOn;
public bool isUp;
void Start()
{
on.SetActive(isOn);
up.SetActive(isUp);
if (isOn)
{
Main.Instance.SwitchChange(1);
}
}
private void OnMouseUp()
{
isUp = !isUp;
isOn = !isOn;
on.SetActive(isOn);
up.SetActive(isUp);
if (isOn)
{
Main.Instance.SwitchChange(1);
}
else
{
Main.Instance.SwitchChange(-1);
}
//Main.Instance.SwitchChange(isOn ? 1 : -1);
}
}
Task Complete Code:
public class Main : MonoBehaviour
{
static public Main Instance;
public int switchCount;
public GameObject winText;
private int onCount = 0;
private void Awake()
{
Instance = this;
winText.SetActive(false);
}
public void SwitchChange(int points) {
onCount = onCount + points;
if (onCount == switchCount)
{
winText.SetActive(true);
}
else
{
winText.SetActive(false);
}
}
}
Comments