1
Fork 0
mirror of https://github.com/Steffo99/beat-td.git synced 2024-11-23 15:54:18 +00:00
beat-td/Assets/Scripts/TowerSelector.cs

52 lines
1.4 KiB
C#
Raw Normal View History

2018-04-22 12:07:55 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TowerSelector : MonoBehaviour {
public GameObject[] towerList;
2018-04-23 11:50:24 +00:00
public int index;
2018-04-22 12:07:55 +00:00
private TowerPlacer towerPlacer;
private SpriteRenderer towerGhost;
2018-04-23 11:50:24 +00:00
void Start () {
2018-04-22 12:07:55 +00:00
index = 0;
towerPlacer = gameObject.GetComponent<TowerPlacer>();
SpriteRenderer[] spriteRenderers = gameObject.GetComponentsInChildren<SpriteRenderer>();
foreach(SpriteRenderer spriteRenderer in spriteRenderers)
{
if(spriteRenderer.gameObject == gameObject)
{
continue;
}
towerGhost = spriteRenderer;
}
}
void Update () {
2018-04-23 11:50:24 +00:00
if (Input.GetAxis("Mouse ScrollWheel") > 0)
2018-04-22 12:07:55 +00:00
{
//Go to the next tower
index++;
if (index >= towerList.Length)
{
index = 0;
}
towerPlacer.selected = towerList[index];
towerGhost.sprite = towerList[index].GetComponent<SpriteRenderer>().sprite;
}
else if (Input.GetAxis("Mouse ScrollWheel") < 0)
{
//Go to the previous tower
index--;
if (index < 0)
{
index = towerList.Length - 1;
}
towerPlacer.selected = towerList[index];
towerGhost.sprite = towerList[index].GetComponent<SpriteRenderer>().sprite;
}
}
}