Commit 86bb2878 by Juliper

not fix yet

parent dc75a488
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -4,76 +4,71 @@ using UnityEngine;
public class BackgroundChanger : MonoBehaviour {
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]);
}
private List<GameObject> backgroundGroup = new List<GameObject>();
private List<GameObject> obstacleGroup = new List<GameObject>();
private GameObject[] gameObjectGroup;
private GameObject background;
private string[] colors = {"Blue", "Green" };
private void CollectBackgrounds()
{
foreach(string color in colors)
{
background = GameObject.FindWithTag(color + "Background");
backgroundGroup.Add(background);
}
}
public void Start()
{
CollectBackgrounds();
CollectObstacles();
UpdateBackgroud(colors[0]);
}
private void CollectObstacles()
{
foreach(string color in colors)
{
obstacle = GameObject.FindWithTag(color + "Obstacle");
obstacleGroup.Add(obstacle);
}
}
private void CollectBackgrounds()
{
background = GameObject.FindWithTag("Background");
}
public void Update()
{
if (Input.GetKey(KeyCode.X))
{
UpdateBackgroud("Blue");
} else if (Input.GetKey(KeyCode.Z))
{
UpdateBackgroud("Green");
}
}
private void CollectObstacles()
{
foreach(string color in colors)
{
gameObjectGroup = GameObject.FindGameObjectsWithTag(color + "Obstacle");
foreach(GameObject obstacle in gameObjectGroup)
{
obstacleGroup.Add(obstacle);
}
}
}
public void UpdateBackgroud(string tagColor)
{
foreach(GameObject background in backgroundGroup)
{
if (background.tag == tagColor + "Background")
{
background.SetActive(true);
} else
{
background.SetActive(false);
}
}
public void Update()
{
if (Input.GetKey(KeyCode.X))
{
UpdateBackgroud("Blue");
} else if (Input.GetKey(KeyCode.Z))
{
UpdateBackgroud("Green");
}
}
UpdateObstacle(tagColor);
}
public void UpdateBackgroud(string tagColor)
{
if(tagColor == "Green")
{
background.GetComponent<SpriteRenderer>().color = new Color32(46, 204, 113, 255);
} else if (tagColor == "Blue")
{
background.GetComponent<SpriteRenderer>().color = new Color32(65, 131, 215, 255);
}
private void UpdateObstacle(string tagColor)
{
foreach (GameObject obstacle in obstacleGroup)
{
if(obstacle.tag == tagColor + "Obstacle")
{
obstacle.SetActive(false);
} else
{
obstacle.SetActive(true);
}
}
}
UpdateObstacle(tagColor);
}
private void UpdateObstacle(string tagColor)
{
foreach (GameObject obstacle in obstacleGroup)
{
if (obstacle.tag == tagColor + "Obstacle")
{
obstacle.SetActive(false);
} else
{
obstacle.SetActive(true);
}
}
}
}
......@@ -8,6 +8,7 @@ TagManager:
- GreenBackground
- BlueObstacle
- GreenObstacle
- Background
layers:
- Default
- TransparentFX
......
<Properties StartupItem="Assembly-CSharp.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\PlayerController.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="Assets\Scripts\BackgroundChanger.cs">
<Files>
<File FileName="Assets\Scripts\BackgroundChanger.cs" Line="32" Column="2" />
<File FileName="Assets\Scripts\PlayerController.cs" Line="14" Column="3" />
<File FileName="Assets\Scripts\BackgroundChanger.cs" Line="22" Column="1" />
<File FileName="Assets\Scripts\PlayerController.cs" Line="1" Column="1" />
<File FileName="Assets\Scripts\PhysicObject.cs" Line="1" Column="1" />
<File FileName="Assets\Scripts\SceneLoader.cs" Line="1" Column="1" />
</Files>
......
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