Skip to content

Instantly share code, notes, and snippets.

@naojitaniguchi
Created May 11, 2017 06:14
Show Gist options
  • Save naojitaniguchi/613d96401676ead02aa2471cf460a2e8 to your computer and use it in GitHub Desktop.
Save naojitaniguchi/613d96401676ead02aa2471cf460a2e8 to your computer and use it in GitHub Desktop.
SwitchObject
using UnityEngine;
using System.Collections;
public class SwitchObj : MonoBehaviour {
public GameObject hart_0;
public GameObject hart_1;
public GameObject hart_2;
public GameObject hart_3;
public GameObject hart_4;
public GameObject hart_5;
public GameObject hart_6;
public GameObject hart_7;
public GameObject hart_8;
public GameObject hart_9;
public float bpm = 60.0f ;
GameObject[] hart_array;
float switchTime ;
float time = 0 ;
int index = 0 ;
// Use this for initialization
void Start () {
hart_array = new GameObject[10];
hart_array[0] = hart_0 ;
hart_array[1] = hart_1 ;
hart_array[2] = hart_2 ;
hart_array[3] = hart_3 ;
hart_array[4] = hart_4 ;
hart_array[5] = hart_5 ;
hart_array[6] = hart_6 ;
hart_array[7] = hart_7 ;
hart_array[8] = hart_8 ;
hart_array[9] = hart_9 ;
for ( int i = 1 ; i < 10 ; i ++ ){
hart_array[i].SetActive(false);
}
switchTime = ( 60.0f / bpm ) / 10.0f ;
}
// Update is called once per frame
void Update () {
time += Time.deltaTime ;
if ( time > switchTime ){
hart_array[index].SetActive(false);
index ++ ;
if ( index >= 10 ){
index = 0 ;
}
hart_array[index].SetActive(true);
time = 0.0f ;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment