void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); return; } else { instance = this; } DontDestroyOnLoad(this.gameObject); }
void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); return; } instance = this; DontDestroyOnLoad(this.gameObject); }
// Use this for initialization void Awake () { if (self != null && self != this) Destroy(this.gameObject); else { source = GetComponent<AudioSource>(); self = this; DontDestroyOnLoad(this.gameObject); } }
void Awake() { if (Instance == null) { Instance = this; } else { Destroy(this.gameObject); } }
void Awake() { if (instance == null) { instance = this; DontDestroyOnLoad(this.gameObject); } else { Destroy(gameObject); } }
private void Awake() { if (_instance != null && _instance != this) { Destroy(this.gameObject); } else { _instance = this; DontDestroyOnLoad(this.gameObject); } }
public void Awake() { if (instance) { DestroyImmediate(gameObject); } else { DontDestroyOnLoad(gameObject); instance = this; } }
private void Awake() { if (Instance == null) { Instance = this; DontDestroyOnLoad(this); } else { Destroy(gameObject); } }
void Awake() { if (instance != null && instance != this) { Destroy(gameObject); } else { instance = this; } DontDestroyOnLoad(gameObject); }
// Use this for initialization void Awake() { mainCamera = GameObject.FindGameObjectWithTag("MainCamera"); if (instance != null && instance != this) { Debug.Log ("singleton exists"); Destroy (this.gameObject); return; } else { instance = this; } DontDestroyOnLoad (this.gameObject); //MoveToMainCamera (); }
// Use this for initialization void Awake() { if (musicSingleton != null) { Destroy(this.gameObject); return; } else { musicSingleton = this; } DontDestroyOnLoad(this.gameObject); }
private void OnEnable() { if (instance != null && instance != this) { Destroy(this.gameObject); return; } else { instance = this; } DontDestroyOnLoad(this.gameObject); }
private void Awake() { if(_instance == null) { //If this is the first instance, make it Singleton _instance = this; DontDestroyOnLoad(this); } else { //If a Singleton already exists and you find another reference in scene, destroy it! if(this != _instance) Destroy(this.gameObject); } }
private IEnumerator coroutine; //So you only need to re-define the coroutines later void Awake() { //If the instance is not null and not the current instance- destroy the game object //This keeps clones from appearing if (instance != null && instance != this) { Destroy(this.gameObject); return; } else { //Otherwise set 'instance' to the current instance instance = this; } //Don destroy this gameobject on loading a new scene DontDestroyOnLoad(this.gameObject); }
void Awake() { if (instance != null && instance != this) { if (instance.GetComponent <AudioSource>().clip != GetComponent <AudioSource>().clip) { instance.GetComponent <AudioSource>().clip = GetComponent <AudioSource>().clip; instance.GetComponent <AudioSource>().volume = GetComponent <AudioSource>().volume; instance.GetComponent <AudioSource>().Play(); } Destroy(this.gameObject); return; } instance = this; GetComponent <AudioSource>().Play(); DontDestroyOnLoad(this.gameObject); }
// Use this for initialization void Start() { //frets = GameObject.FindGameObjectsWithTag ("Fret"); MusicSingleton.Stop(); //print (GameObject.FindGameObjectWithTag("FailedButton").name); sButton = GameObject.FindGameObjectWithTag("SuccessButton"); fButton = GameObject.FindGameObjectWithTag("FailedButton"); sButton.SetActive(false); fButton.SetActive(false); time.text = "Time : " + ((int)now).ToString() + " s"; fretButtons = GameObject.FindObjectsOfType <Button>().OrderBy(go => go.name).ToArray(); frequencys = new MinMaxFreq[fretNumbers.Length]; for (int i = 0; i < fretNumbers.Length; i++) { fretButtons [i].GetComponentInChildren <Text> ().text = fretNumbers[i].ToString(); //print (fretButtons[i].name.ToString() + " " +fretButtons [i].GetComponentInChildren<Text> ().text); // Initialize all needed frequencys int tmp = fretNumbers [i]; tmp = tmp + (STRING - stringNumbers [i]) * 5; if (stringNumbers[i] <= 2) { tmp = tmp - 1; } //print (tmp); if (tmp == 0) { frequencys [i].min = 79.0f; frequencys [i].max = (teoFreqs [tmp] + teoFreqs [tmp + 1]) / 2.0f; } else { // TODO kalau tmp nya nilai string max //print (tmp); //print (tmp-1); //print (tmp-i); frequencys [i] = new MinMaxFreq(); frequencys [i].min = (teoFreqs [tmp] + teoFreqs [tmp - 1]) / 2.0f; frequencys [i].max = (teoFreqs [tmp + 1] + teoFreqs [tmp]) / 2.0f; } } }
void Awake() { if (instance != null && instance != this) { if(instance.GetComponent<AudioSource>().clip != GetComponent<AudioSource>().clip) { instance.GetComponent<AudioSource>().clip = GetComponent<AudioSource>().clip; instance.GetComponent<AudioSource>().volume = GetComponent<AudioSource>().volume; instance.GetComponent<AudioSource>().Play(); } Destroy(this.gameObject); return; } instance = this; GetComponent<AudioSource>().Play (); DontDestroyOnLoad(this.gameObject); }
public void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); return; } else { instance = this; musicManager = this.gameObject; } GetComponent <AudioSource>().clip = music; GetComponent <AudioSource>().Play(); DontDestroyOnLoad(this.gameObject); }
// Use this for initialization void Awake() { musicAudio = GetComponent <AudioSource> (); if (instance != null && instance != this) // If there is an existing music player { Destroy(this.gameObject); // Destroy this one, don't need to return; // skip the rest } else // Otherwise { instance = this; // There is no music player, use this } DontDestroyOnLoad(this.gameObject); // Don't destroy when the scene loads (object script is attached to) musicAudio.clip = clip; // Load the clip musicAudio.Play(); // Start playing my awesome menu music }
void Awake() { if (instance != null && instance != this) { if (!instance.aSource.isPlaying) { instance.aSource.Play(); } Destroy(this.gameObject); return; } else { instance = this; if (!instance.aSource.isPlaying) { instance.aSource.Play(); } } DontDestroyOnLoad(this.gameObject); }
void Awake() { if (instance != null && instance != this) { AudioSource existingAudio = instance.audio;; if (existingAudio.clip.name != audio.clip.name) { existingAudio.Stop(); existingAudio.clip = audio.clip; existingAudio.Play(); } Destroy(this.gameObject); Destroy(audio.gameObject); return; } else { instance = this; DontDestroyOnLoad(this.gameObject); DontDestroyOnLoad(audio.gameObject); audio.Play(); if (audio.clip.name == "destoroya") { //TODO clip the mp3 instead audio.time = 13.3f; } } }
// Use this for initialization void Start() { music = MusicSingleton.Instance (); }
// Use this for initialization void Start() { LoadFile(); MusicSingleton.Stop(); //print (GameObject.FindGameObjectWithTag("FailedButton").name); sButton = GameObject.FindGameObjectWithTag("SuccessButton"); fButton = GameObject.FindGameObjectWithTag("FailedButton"); time.text = "Time : " + ((int)now).ToString() + " s"; fretButtons = GameObject.FindObjectsOfType <Button>().OrderBy(go => go.name).ToArray(); fretNumInTab = new int[fretNumbers.Count]; for (int j = 0; j < fretNumbers.Count; j++) { if (j == 0) { fretNumInTab [j] = fretNumbers [j].Length; } else { fretNumInTab [j] = fretNumbers [j].Length + fretNumInTab[j - 1]; } } frequencys = new MinMaxFreq[fretNumInTab[fretNumInTab.Length - 1]]; for (int j = 0; j < fretNumbers.Count; j++) { for (int i = 0; i < fretNumbers[j].Length; i++) { int padding = 0; if (j != 0) { padding = fretNumInTab [j - 1]; } fretButtons [padding + i].GetComponentInChildren <Text> ().text = fretNumbers[j][i].ToString(); //print ("position : "+fretButtons[padding+i].transform.position.x); // place fret to designed place fretButtons [padding + i].GetComponent <RectTransform> ().position = fretButtons [padding + i].GetComponent <RectTransform> ().position + /*new Vector3(54.0f,-32.0f);*/ new Vector3((distanceX * i), (distanceY * (stringNumbers [j] [i] - 1))); fretButtons [padding + i].gameObject.SetActive(false); //toBeChanged = true; // Initialize all needed frequencys int tmp = fretNumbers [j][i]; tmp = tmp + (STRING - stringNumbers [j][i]) * 5; if (stringNumbers[j][i] <= 2) { tmp = tmp - 1; } //print (tmp); if (tmp == 0) { frequencys [padding + i].min = 79.0f; frequencys [padding + i].max = (teoFreqs [tmp] + teoFreqs [tmp + 1]) / 2.0f; } else { // TODO kalau tmp nya nilai string max //print (tmp); //print (tmp-1); //print (tmp-i); frequencys [padding + i] = new MinMaxFreq(); frequencys [padding + i].min = (teoFreqs [tmp] + teoFreqs [tmp - 1]) / 2.0f; frequencys [padding + i].max = (teoFreqs [tmp + 1] + teoFreqs [tmp]) / 2.0f; } } } int initial = fretNumbers.Count >= 2 ? 1 : 0; for (int i = 0; i < fretNumInTab[initial]; i++) { fretButtons [i].gameObject.SetActive(true); } }
public void Start() { GameObject backgroundMusic = GameObject.FindGameObjectWithTag ("BackgroundMusic"); musicSingleton = MusicSingleton.Instance (); }
// Update is called once per frame void Update() { if(musicSingleton == null) { if(MusicSingleton.Instance != null) { musicSingleton = MusicSingleton.Instance; restoreVolume = musicSingleton.volume; } } else { if(sequenceTimer < sequenceTime) { musicSingleton.volume -= .5f * Time.deltaTime; } else if (sequenceTimer <= 0) { musicSingleton.volume = restoreVolume; } } sequenceTimer -= Time.deltaTime; if (sequenceTimer < sequenceTime - 1) { if (!soundEffect.isPlaying && sequenceTimer > 10) { soundEffect.Play(); } } if(sequenceTimer > (sequenceTime - 2)) { currentStage = launchStage.Stationary; } else if(sequenceTimer > (sequenceTime - 4) && sequenceTimer < (sequenceTime - 2)) { currentStage = launchStage.FiringUp; //gameObject.GetComponent<Camera>().orthographicSize -= .01f * Time.deltaTime; } else if(sequenceTimer > (sequenceTime - 7) && sequenceTimer < (sequenceTime - 4)) { currentStage = launchStage.LiftOff; } else { currentStage = launchStage.Cruise; } Vector3 rocketPos = rocket.transform.position; switch(currentStage) { case launchStage.Stationary: rocketThrust.particleInterval = .5f; break; case launchStage.FiringUp: rocketThrust.particleInterval = .1f; rocketPos.y += .1f * Time.deltaTime * (10.0f / sequenceTimer); rocket.transform.position = rocketPos; rocket.transform.Rotate(0, 0, Random.Range(-.25f, .25f)); break; case launchStage.LiftOff: rocketThrust.particleInterval = .02f; rocketPos.y += 4.0f * Time.deltaTime; rocket.transform.position = rocketPos; if (rocket.transform.rotation.z < -1.0f || rocket.transform.rotation.z > 359.0f) { rocket.transform.Rotate(0, 0, Random.Range(0.0f, .15f)); } else if(rocket.transform.rotation.z > 1.0) { rocket.transform.Rotate(0, 0, Random.Range(-0.15f, 0.0f)); } else { rocket.transform.Rotate(0, 0, Random.Range(-.3f, .3f)); } break; //Default is standin for cruise default: rocketThrust.particleInterval = 0.001f; rocketPos.y += 3.5f * Time.deltaTime; rocket.transform.position = rocketPos; if (rocket.transform.rotation.z < - .03f || rocket.transform.rotation.z > 360.0f - .03f) { rocket.transform.Rotate(0, 0, Random.Range(0.0f, .03f)); } else if (rocket.transform.rotation.z > .03f) { rocket.transform.Rotate(0, 0, Random.Range(-0.03f, 0.0f)); } else { //rocket.transform.rotation.SetEulerAngles(0, 0, 0); } break; } if(rocket.transform.position.y > transform.position.y && transform.position.y < 35.0f) { Vector3 cameraPos = transform.position; cameraPos.y = rocket.transform.position.y; if(cameraPos.x < rocket.transform.position.x) { cameraPos.x += 2 * Time.deltaTime; } transform.position = cameraPos; } else if(transform.position.y > 35.0f) { Color black = GetComponentInChildren<SpriteRenderer>().color; black.a += .28f * Time.deltaTime; GetComponentInChildren<SpriteRenderer>().color = black; if(black.a >= 1) { if(musicSingleton != null) { musicSingleton.audioPlayer.Stop(); musicSingleton.volume = restoreVolume; } Application.LoadLevel("InsideShip"); } } }