Last active
December 1, 2020 03:27
-
-
Save gremito/37327dabebc8f72bc7517fb3ccef72b0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class InstantiateManager : MonoBehaviour | |
{ | |
[SerializeField] | |
private GameObject _cube; | |
private int _frameCount; | |
enum ColorStatus { red, blue, green }; | |
ColorStatus _status; | |
void Start() | |
{ | |
_frameCount = 0; | |
_status = ColorStatus.red; | |
} | |
void Update() | |
{ | |
_frameCount++; | |
if (_frameCount >= 60) | |
{ | |
_frameCount = 0; | |
var go = Instantiate(_cube); | |
switch (_status) | |
{ | |
case ColorStatus.red: | |
go.GetComponent<Renderer>().material.color = Color.red; | |
_status = ColorStatus.blue; | |
break; | |
case ColorStatus.blue: | |
go.GetComponent<Renderer>().material.color = Color.blue; | |
_status = ColorStatus.green; | |
break; | |
case ColorStatus.green: | |
go.GetComponent<Renderer>().material.color = Color.green; | |
_status = ColorStatus.red; | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment