-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitchStage.cs
54 lines (52 loc) · 1.57 KB
/
SwitchStage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class SwitchStage : MonoBehaviour {
public int ThisLvl;
private int CurrentLevel;
private int CurrentLevels;
private int LVLreq;
public bool SwitchCond;
public int levelRequirement;
public
// Use this for initialization
void Start()
{
CurrentLevel = SceneManager.GetActiveScene().buildIndex;
for (int i = 0; i <= GameObject.FindObjectsOfType<SwitchStage>().Length + 1; i ++)
{
LVLreq += PlayerPrefs.GetInt(i.ToString());
}
}
void OnTriggerEnter2D(Collider2D Col2d)
{
if (SwitchCond && Col2d.gameObject.tag == "Contravert")
{
PlayerPrefs.SetInt(CurrentLevel.ToString(), 1);
SceneManager.LoadScene("Level select");
}
Debug.Log(Col2d);
}
void OnMouseDown()
{
Debug.Log(LVLreq);
if (!SwitchCond && LVLreq >= levelRequirement)
SceneManager.LoadScene(ThisLvl +1);
}
void Update()
{
if (!SwitchCond)
{
if (LVLreq < levelRequirement)
GetComponent<SpriteRenderer>().color = Color.clear;
else if (PlayerPrefs.GetInt(ThisLvl.ToString()) == 0)
GetComponent<SpriteRenderer>().color = Color.white;
else
GetComponent<SpriteRenderer>().color = Color.blue;
}
else
{
transform.Rotate(Vector3.forward, -360 * Time.deltaTime);
}
}
}