public void setMaxHP(int value) { if (value == PlayerCharacter.instance.MaxHP) { return; } if (value <= 0) { setHP(0); return; } if (value > ControlPanel.instance.HPLimit) { value = ControlPanel.instance.HPLimit; } else if (PlayerCharacter.instance.HP > value) { PlayerCharacter.instance.HP = value; } else { UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound("healsound").name); } PlayerCharacter.instance.MaxHPShift = value - PlayerCharacter.instance.BasisMaxHP; }
public void Dust(bool playDust = true, bool removeObject = false) { if (tag == "enemy" || tag == "bubble") { throw new CYFException("sprite.Dust(): You can't dust a " + tag + "'s sprite!"); } GameObject go = Object.Instantiate(Resources.Load <GameObject>("Prefabs/MonsterDuster")); go.transform.SetParent(UIController.instance.psContainer.transform); if (playDust) { UnitaleUtil.PlaySound("DustSound", AudioClipRegistry.GetSound("enemydust")); } img.GetComponent <ParticleDuplicator>().Activate(this); if (img.gameObject.name == "player") { return; } img.SetActive(false); if (removeObject) { Remove(); } }
public void setHP(float newhp, bool forced = false) { if (newhp <= 0) { EventManager.instance.luaGeneralOw.GameOver(); return; } float CheckedHP = PlayerCharacter.instance.HP; UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound(CheckedHP - newhp >= 0 ? "hurtsound" : "healsound").name); newhp = Mathf.Round(newhp * Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma)) / Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma); if (forced) { CheckedHP = newhp > PlayerCharacter.instance.MaxHP * 1.5 ? (int)(PlayerCharacter.instance.MaxHP * 1.5) : newhp; } else { CheckedHP = newhp > PlayerCharacter.instance.MaxHP ? PlayerCharacter.instance.MaxHP : newhp; } if (CheckedHP > ControlPanel.instance.HPLimit) { CheckedHP = ControlPanel.instance.HPLimit; } PlayerCharacter.instance.HP = CheckedHP; }
public void Hurt(int damage) { if (damage >= 0) { UnitaleUtil.PlaySound("HurtSound", AudioClipRegistry.GetSound("hurtsound"), 0.65f); } else { UnitaleUtil.PlaySound("HurtSound", AudioClipRegistry.GetSound("healsound"), 0.65f); } if (-damage + player.HP > player.MaxHP) { player.HP = player.MaxHP; } else if (-damage + player.HP <= 0) { player.HP = 1; } else { player.HP -= damage; } appliedScript.Call("CYFEventNextCommand"); }
public void setHP(float newhp, bool forced = false) { if (newhp <= 0) { GameOverBehavior gob = GameObject.FindObjectOfType <GameOverBehavior>(); if (!MusicManager.IsStoppedOrNull(PlayerOverworld.audioKept)) { gob.musicBefore = PlayerOverworld.audioKept; gob.music = gob.musicBefore.clip; gob.musicBefore.Stop(); } else if (!MusicManager.IsStoppedOrNull(Camera.main.GetComponent <AudioSource>())) { gob.musicBefore = Camera.main.GetComponent <AudioSource>(); gob.music = gob.musicBefore.clip; gob.musicBefore.Stop(); } else { gob.musicBefore = null; gob.music = null; } player.HP = 0; gob.gameObject.transform.SetParent(null); GameObject.DontDestroyOnLoad(gob.gameObject); RectTransform rt = gob.gameObject.GetComponent <RectTransform>(); rt.position = new Vector3(rt.position.x, rt.position.y, -1000); gob.gameObject.GetComponent <GameOverBehavior>().StartDeath(); return; } float CheckedHP = player.HP; if (CheckedHP - newhp >= 0) { UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound("hurtsound").name); } else { UnitaleUtil.PlaySound("CollisionSoundChannel", AudioClipRegistry.GetSound("healsound").name); } newhp = Mathf.Round(newhp * Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma)) / Mathf.Pow(10, ControlPanel.instance.MaxDigitsAfterComma); if (forced) { CheckedHP = newhp > player.MaxHP * 1.5 ? (int)(player.MaxHP * 1.5) : newhp; } else { CheckedHP = newhp > player.MaxHP ? player.MaxHP : newhp; } if (CheckedHP > ControlPanel.instance.HPLimit) { CheckedHP = ControlPanel.instance.HPLimit; } player.HP = CheckedHP; }
public static void PlaySound(string name, float volume = 0.65f) { if (name == null) { throw new CYFException("Attempted to load a nil value as a sound."); } UnitaleUtil.PlaySound("MusicPlaySound", AudioClipRegistry.GetSound(name), volume); }
/// <summary> /// Plays a selected sound at a given volume. /// </summary> /// <param name="sound"></param> /// <param name="volume"></param> [CYFEventFunction] public void PlaySound(string sound, float volume = 0.65f) { volume = Mathf.Clamp01(volume); if (AudioClipRegistry.GetSound(sound) == null) { throw new CYFException("General.PlaySound: The given BGM doesn't exist. Please check if you've spelled it correctly."); } UnitaleUtil.PlaySound("PlaySound", AudioClipRegistry.GetSound(sound), volume); //GameObject.Find("Player").GetComponent<AudioSource>().PlayOneShot(AudioClipRegistry.GetSound(sound), volume); appliedScript.Call("CYFEventNextCommand"); }
public static void PlaySound(string name, float volume = 0.65f) { if (name == null) { UnitaleUtil.WriteInLogAndDebugger("[WARN]Attempted to load a nil value as a sound."); return; } try { UnitaleUtil.PlaySound("MusicPlaySound", AudioClipRegistry.GetSound(name), volume); } catch { } }
public static bool PlaySound(string name, float volume = 0.65f) { if (name == null) { UnitaleUtil.WriteInLogAndDebugger("[WARN]Attempted to load a nil value as a sound."); return(false); } try { UnitaleUtil.PlaySound("MusicPlaySound", AudioClipRegistry.GetSound(name, GlobalControls.retroMode), volume); return(true); } catch { return(false); } }
public void Hurt(int damage) { UnitaleUtil.PlaySound("HurtSound", AudioClipRegistry.GetSound(damage >= 0 ? "hurtsound" : "healsound")); if (-damage + PlayerCharacter.instance.HP > PlayerCharacter.instance.MaxHP) { PlayerCharacter.instance.HP = PlayerCharacter.instance.MaxHP; } else if (-damage + PlayerCharacter.instance.HP <= 0) { PlayerCharacter.instance.HP = 1; } else { PlayerCharacter.instance.HP -= damage; } appliedScript.Call("CYFEventNextCommand"); }
public void Dust(bool playDust = true, bool removeObject = false) { if (tag == "enemy" || tag == "bubble") { return; } GameObject go = GameObject.Instantiate(MonsterDusterPrefab); go.transform.SetParent(UIController.instance.psContainer.transform); if (playDust) { UnitaleUtil.PlaySound("DustSound", AudioClipRegistry.GetSound("enemydust")); } img.GetComponent <ParticleDuplicator>().Activate(this); if (img.gameObject.name != "player") { img.SetActive(false); if (removeObject) { img = null; } } }
void HandleAction() { switch (currentState) { case State.EXIT: break; case State.MENU: switch (selection) { case 0: ChangeState(State.BUY, 0); break; case 1: ChangeState(State.SELL, 0); break; case 2: ChangeState(State.TALK, 0); break; case 3: HandleCancel(); break; } break; case State.BUY: if (selection == numberOfChoices - 1) { HandleCancel(); } else { ChangeState(State.BUYCONFIRM, 0); if (mainPrice[currentItemIndex] == 0) { TryCall("FailBuy", DynValue.NewString("soldout")); HandleCancel(); } } break; case State.SELL: if (selection == numberOfChoices - 1) { HandleCancel(); } else { ChangeState(State.SELLCONFIRM, 0); if (Inventory.NametoPrice[Inventory.inventory[currentItemIndex].Name] == 0) { UnitaleUtil.PlaySound("SeparateSound", "ShopFail"); TryCall("FailSell", DynValue.NewString("cantsell")); HandleCancel(); } } break; case State.TALK: if (selection == numberOfChoices - 1) { HandleCancel(); } else { ChangeState(State.TALKINPROGRESS); } break; case State.BUYCONFIRM: if (selection == numberOfChoices - 1) { TryCall("ReturnBuy"); } else { if (PlayerCharacter.instance.Gold < mainPrice[currentItemIndex]) { TryCall("FailBuy", DynValue.NewString("gold")); } else if (Inventory.inventory.Count == Inventory.inventorySize) { TryCall("FailBuy", DynValue.NewString("full")); } else if (mainPrice[currentItemIndex] == 0) { TryCall("FailBuy", DynValue.NewString("soldout")); } else { TryCall("SuccessBuy", DynValue.NewString(mainName[currentItemIndex])); UnitaleUtil.PlaySound("SeparateSound", "ShopSuccess"); PlayerCharacter.instance.SetGold(PlayerCharacter.instance.Gold - mainPrice[currentItemIndex]); Inventory.AddItem(mainName[currentItemIndex]); tmGold.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + PlayerCharacter.instance.Gold + "G", false, true) }); tmItem.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + Inventory.inventory.Count + "/8", false, true) }); } } if (!interrupted) { selection = currentItemIndex; HandleCancel(); } break; case State.SELLCONFIRM: if (selection == numberOfChoices - 1) { TryCall("ReturnSell"); } else { TryCall("SuccessSell", DynValue.NewString(mainName[currentItemIndex])); UnitaleUtil.PlaySound("SeparateSound", "ShopSuccess"); PlayerCharacter.instance.SetGold(PlayerCharacter.instance.Gold + Inventory.NametoPrice[Inventory.inventory[currentItemIndex].Name] / 5); Inventory.RemoveItem(currentItemIndex); if (currentItemIndex == Inventory.inventory.Count && Inventory.inventory.Count != 1) { currentItemIndex--; } } if (!interrupted) { selection = currentItemIndex; HandleCancel(); } break; } }
// Update is called once per frame void Update() { if (GlobalControls.input.Confirm == UndertaleInput.ButtonState.PRESSED) { List <UnderItem> selectedInv = inventoryColumn ? Inventory.inventory : ItemBox.items; List <UnderItem> otherInv = inventoryColumn ? ItemBox.items : Inventory.inventory; int otherInvCapacity = inventoryColumn ? ItemBox.capacity : Inventory.inventorySize; if (lineIndex < selectedInv.Count) { UnderItem item = selectedInv[lineIndex]; if (otherInv.Count < otherInvCapacity) { if (inventoryColumn) { ItemBox.AddToBox(item.Name); Inventory.RemoveItem(lineIndex); } else { Inventory.AddItem(item.Name); ItemBox.RemoveFromBox(lineIndex); } UnitaleUtil.PlaySound("SeparateSound", "menuconfirm"); } else { UnitaleUtil.PlaySound("SeparateSound", "menumove"); } } else { UnitaleUtil.PlaySound("SeparateSound", "menumove"); } RefreshDisplay(); } else if (GlobalControls.input.Up == UndertaleInput.ButtonState.PRESSED) { lineIndex--; if (lineIndex < 0) { lineIndex = (inventoryColumn ? Inventory.inventorySize : ItemBox.capacity) - 1; } UnitaleUtil.PlaySound("SeparateSound", "menumove"); RefreshDisplay(); } else if (GlobalControls.input.Down == UndertaleInput.ButtonState.PRESSED) { lineIndex++; if (lineIndex >= (inventoryColumn ? Inventory.inventorySize : ItemBox.capacity)) { lineIndex = 0; } UnitaleUtil.PlaySound("SeparateSound", "menumove"); RefreshDisplay(); } else if (GlobalControls.input.Left == UndertaleInput.ButtonState.PRESSED || GlobalControls.input.Right == UndertaleInput.ButtonState.PRESSED) { if (lineIndex < Inventory.inventorySize && lineIndex < ItemBox.capacity) { inventoryColumn = !inventoryColumn; UnitaleUtil.PlaySound("SeparateSound", "menumove"); RefreshDisplay(); } } else if (GlobalControls.input.Cancel == UndertaleInput.ButtonState.PRESSED) { UnitaleUtil.PlaySound("SeparateSound", "menumove"); DestroySelf(); } }
public static void PlaySound(string name, float volume = 0.65f) { try { UnitaleUtil.PlaySound("MusicPlaySound", AudioClipRegistry.GetSound(name), volume); } catch { } }
public static void PlaySound(AudioClip clip) { UnitaleUtil.PlaySound("CollisionSoundChannel", clip.name); }