private IEnumerator Scale(Vector2 targetScale, BinocularsState currentState) { bool revert = false; Vector2 initialScale = gameObject.transform.localScale; float progress = 0; while (progress <= 1) { if (cancelScale && !revert && targetScale.x > initialScale.x) { targetScale = initialScale; initialScale = transform.localScale; progress = 0; revert = true; } transform.localScale = Vector2.Lerp(initialScale, targetScale, progress); progress += Time.deltaTime * timeScale; yield return(null); } transform.localScale = targetScale; busy = false; if (revert) { state = currentState; if (state != BinocularsState.unequiped) { reversed = !reversed; } } }
void ToggleBinoculars() { busy = true; if (state == BinocularsState.unequiped) { if (reversed) { StartCoroutine(Scale(scaleDown, state)); state = BinocularsState.reversed; //equiped AkSoundEngine.PostEvent("BigUnequip", this.gameObject); } else { StartCoroutine(Scale(scaleUp, state)); state = BinocularsState.equiped; //reversed AkSoundEngine.PostEvent("SmallUnequip", this.gameObject); } } else { if (state == BinocularsState.equiped) { AkSoundEngine.PostEvent("BigUnequip", this.gameObject); } else { AkSoundEngine.PostEvent("SmallUnequip", this.gameObject); } StartCoroutine(Scale(originalScale, state)); //unqeuip state = BinocularsState.unequiped; } }
void TurnBinoculars() { busy = true; if (reversed) { StartCoroutine(Scale(scaleUp, state)); state = BinocularsState.equiped; //equiped reversed = false; AkSoundEngine.PostEvent("SmallUnequip", this.gameObject); } else { StartCoroutine(Scale(scaleDown, state)); state = BinocularsState.reversed; //reversed reversed = true; AkSoundEngine.PostEvent("BigUnequip", this.gameObject); } }
// Start is called before the first frame update void Start() { InitializeBools(); state = BinocularsState.unequiped; originalScale = gameObject.transform.localScale; }