Commit 08f5c2da by Eko Simanjuntak

add backgroundChanger

parent 1801f02a
......@@ -4,13 +4,76 @@ using UnityEngine;
public class BackgroundChanger : MonoBehaviour {
// Use this for initialization
void Start () {
private List<GameObject> backgroundGroup = new List<GameObject>();
private List<GameObject> obstacleGroup = new List<GameObject>();
private GameObject[] gameObjectGroup;
private GameObject background;
private GameObject obstacle;
private string[] colors = {"Blue", "Green" };
public void Start()
{
CollectBackgrounds();
CollectObstacles();
UpdateBackgroud(colors[0]);
}
// Update is called once per frame
void Update () {
private void CollectBackgrounds()
{
foreach(string color in colors)
{
background = GameObject.FindWithTag(color + "Background");
backgroundGroup.Add(background);
}
}
private void CollectObstacles()
{
foreach(string color in colors)
{
obstacle = GameObject.FindWithTag(color + "Obstacle");
obstacleGroup.Add(obstacle);
}
}
public void Update()
{
if (Input.GetKey(KeyCode.X))
{
UpdateBackgroud("Blue");
} else if (Input.GetKey(KeyCode.Z))
{
UpdateBackgroud("Green");
}
}
public void UpdateBackgroud(string tagColor)
{
foreach(GameObject background in backgroundGroup)
{
if (background.tag == tagColor + "Background")
{
background.SetActive(true);
} else
{
background.SetActive(false);
}
}
UpdateObstacle(tagColor);
}
private void UpdateObstacle(string tagColor)
{
foreach (GameObject obstacle in obstacleGroup)
{
if(obstacle.tag == tagColor + "Obstacle")
{
obstacle.SetActive(false);
} else
{
obstacle.SetActive(true);
}
}
}
}
......@@ -4,7 +4,10 @@
TagManager:
serializedVersion: 2
tags:
- Background
- BlueBackground
- GreenBackground
- BlueObstacle
- GreenObstacle
layers:
- Default
- TransparentFX
......
File deleted
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment