public static void CreateDamagePopUp(string text, Vector2 location, bool IsCrit, DamageType damageType) { PopUpText instance = Instantiate(popUpText); instance.transform.SetParent(canvas.transform, false); Vector2 position = new Vector2(Random.Range(-location.x, location.x) + Random.Range(minRandomValue, maxRandomValue), location.y + Random.Range(minRandomValue, maxRandomValue)); instance.transform.position = location; instance.SetText(text); if (IsCrit) { instance.SetFontSize(critFontsize); instance.SetColor(critColor); } if (damageType == DamageType.Fire) { instance.SetFontSize(effectsFontsize); instance.SetColor(fireColor); } if (damageType == DamageType.Bleeding) { instance.SetFontSize(effectsFontsize); instance.SetColor(bleedColor); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "HP") { sounds.PlayOneShot(healthSound); Destroy(collision.gameObject); if (PlayerStats.getIstance().getHealthPoints() < 3) { PlayerStats.getIstance().healthGain(); } else { PopUpText.fillPopUp("Vida cheia!"); StartCoroutine(WaitPopUp()); } } else if (collision.gameObject.tag == "Points") { sounds.PlayOneShot(coinSound); PlayerStats.getIstance().addPoints(); Destroy(collision.gameObject); } else if (collision.gameObject.tag == "EndOfLevel") { SceneManager.LoadScene(nextScene); } }
void WrongAnwserResponse(Button btnWrong) { PopUpText.fillPopUp("Resposta Errada!!!"); paintButtons(btnWrong); sounds.PlayOneShot(wrongAnswerSound); PlayerStats.getIstance().healthLoss(); }
public static void CreateDamagePopUp(string text, Vector3 location, DamageType damageType) { if (popUpText == null) { Initialize(); } PopUpText instance = Instantiate(popUpText); instance.transform.SetParent(canvas.transform, false); Vector3 position = new Vector3(location.x + Random.Range(minRandomValue, maxRandomValue), location.y + Random.Range(minRandomValue, maxRandomValue), location.z + Random.Range(minRandomValue, maxRandomValue)); instance.transform.position = location; instance.SetText(text); if (damageType == DamageType.Normal) { instance.SetFontSize(defaultFontSize); instance.SetColor(normalColor); } else if (damageType == DamageType.Fire) { instance.SetFontSize(smallerFontSize); instance.SetColor(fireColor); } }
private IEnumerator SendGoblinInCaveRoutine(Goblin g) { CaveView.CloseCave(); //Goblin walk there g.MoveTo(transform.position); //Wait for resolution yield return(new WaitForSeconds(2)); //turn off goblin g.gameObject.SetActive(false); //Wait for resolution yield return(new WaitForSeconds(2)); //Arrive back with treasure or Remove goblin if (Random.Range(0, g.SMA.GetStatMax()) >= Difficulty) { g.Xp += 10; g.Team.OnTreasureFound.Invoke(Prize); PopUpText.ShowText(g.name + " found many goblin treasures in Cave!"); g.gameObject.SetActive(true); g.ChangeState(Character.CharacterState.Idling, true); Explored = true; } else { PopUpText.ShowText(g + " did not return from exploring the cave!"); g.Health = 0; g.Team.Members.Remove(g); } }
//TODO: move to general POI method private IEnumerator Spawning() { if (HasBeenAttacked) { yield break; } HasBeenAttacked = true; yield return(new WaitForSeconds(0.5f)); var spawn = new List <Character>(); for (int i = 0; i < EnemiesOnAttack; i++) { var z = MapGenerator.GenerateCharacter(SpawnEnemies[Random.Range(0, SpawnEnemies.Length)], InArea, NpcHolder.Instance.transform, true).GetComponent <Character>(); z.ChangeState(Character.CharacterState.Attacking); spawn.Add(z); yield return(new WaitForSeconds(Random.Range(0, 1.5f))); } if (WinCondition) { yield return(new WaitUntil(() => spawn.All(s => !s.Alive()))); Debug.Log("PLAYER HAS WON"); PopUpText.ShowText("The goblins have found a new home!"); SoundController.PlayStinger(SoundBank.Stinger.GameWin); } }
public void PopUp(int damage, Vector2 _position) { PopUpText _text = GCManager.Instantiate(DAMAGE_POPUP_GC_KEY).GetComponentInChildren <PopUpText>(); _text.SetText(damage.ToString()); _text.transform.position = _position; }
public void DisplayNextQuestion() { ResetButtonColor(); RemoveAllButtonListeners(); cantBeThisValues.Clear(); helpCalls = 0; PopUpText.fillPopUp(""); if (questions.Count == 0) { EndQuestions(); return; } string question = questions.Dequeue(); string ans1 = answers1queue.Dequeue(); string ans2 = answers2queue.Dequeue(); string ans3 = answers3queue.Dequeue(); string ans4 = answers4queue.Dequeue(); int rightAns = rightAnswerqueue.Dequeue(); questionText.text = question; answer1Text.text = ans1; answer2Text.text = ans2; answer3Text.text = ans3; answer4Text.text = ans4; if (rightAns == 1) { btn1.onClick.AddListener(RightAnwserResponse); btn2.onClick.AddListener(delegate { WrongAnwserResponse(btn2); }); btn3.onClick.AddListener(delegate { WrongAnwserResponse(btn3); }); btn4.onClick.AddListener(delegate { WrongAnwserResponse(btn4); }); } else if (rightAns == 2) { btn1.onClick.AddListener(delegate { WrongAnwserResponse(btn1); }); btn2.onClick.AddListener(RightAnwserResponse); btn3.onClick.AddListener(delegate { WrongAnwserResponse(btn3); }); btn4.onClick.AddListener(delegate { WrongAnwserResponse(btn4); }); } else if (rightAns == 3) { btn1.onClick.AddListener(delegate { WrongAnwserResponse(btn1); }); btn2.onClick.AddListener(delegate { WrongAnwserResponse(btn2); }); btn3.onClick.AddListener(RightAnwserResponse); btn4.onClick.AddListener(delegate { WrongAnwserResponse(btn4); }); } else if (rightAns == 4) { btn1.onClick.AddListener(delegate { WrongAnwserResponse(btn1); }); btn2.onClick.AddListener(delegate { WrongAnwserResponse(btn2); }); btn3.onClick.AddListener(delegate { WrongAnwserResponse(btn3); }); btn4.onClick.AddListener(RightAnwserResponse); } ajuda.onClick.AddListener(delegate { HelpButton(rightAns); }); }
public void CreatePopupText(string text, Transform location) { PopUpText instance = Instantiate(popUpTextPrefab); instance.transform.SetParent(canvas.transform, false); instance.transform.position = location.position; instance.SetText(text); }
// Start is called before the first frame update void Awake() { if (!Instance) { Instance = this; } PopText.text = ""; }
public static void Initialize() { canvas = GameObject.FindGameObjectWithTag("DamagePopUp"); if (!popUpText) { popUpText = Resources.Load <PopUpText>("Prefabs/UI/DamageTextPopUp"); } }
public static void CreateDamageText(string text, Transform location) { PopUpText instance = Instantiate(damageText); Vector2 screenPosition = camera.WorldToScreenPoint(location.position); instance.transform.SetParent(canvas.transform, false); instance.transform.position = screenPosition; instance.SetText(text); }
public void SetPopUp() { GameObject foundGameObject = GameObject.Find("P_PopUpText(Clone)"); GameObject textObject = Instantiate(myTextObject, foundGameObject.transform); Vector3 myNewPosition = gameObject.transform.position; myNewPosition.y = myNewPosition.y + 1f; textObject.transform.position = myNewPosition; myPopUpText = textObject.GetComponent <PopUpText>(); }
public PopUpText SpawnPopUpText(string str, Vector3 position, Color color) { PopUpText popUpTextPrefab = (PopUpText)Instantiate(m_PopUpTextPrefab, position + m_PopUpTextOffset, Quaternion.identity); popUpTextPrefab.SetText(str); popUpTextPrefab.SetColor(color); return(popUpTextPrefab); }
void Awake() { if (Instance) { Destroy(this); } else { Instance = this; } }
public void CreatePopText(string text, Transform location) { PopUpText instance = Instantiate(popUpTextPreFab); //Vector2 screen_position = Camera.main.WorldToScreenPoint(location.position); Vector2 screen_position = new Vector2(location.position.x, location.position.y); instance.transform.SetParent(canvas.transform, false); instance.transform.position = screen_position; instance.SetText(text); }
void HelpButton(int rightAns) { helpCalls++; if (helpCalls <= 2) { if (!cantBeThisValues.Contains(rightAns)) { cantBeThisValues.Add(rightAns); } if (PlayerStats.getIstance().getPoints() < 100) { PopUpText.fillPopUp("Pontos insuficientes! São necessários no mínimo 100 pontos para pedir ajuda!"); StartCoroutine(WaitPopUp()); } else { PlayerStats.getIstance().usePoints(); int randomNumber = Random.Range(1, 4); while (verifyHelp(randomNumber, cantBeThisValues)) { randomNumber = Random.Range(1, 4); } switch (randomNumber) { case 1: paintButtons(btn1); break; case 2: paintButtons(btn2); break; case 3: paintButtons(btn3); break; case 4: paintButtons(btn4); break; } cantBeThisValues.Add(randomNumber); } } else if (helpCalls == 20) { PopUpText.fillPopUp("Você não cansa de apertar esse botão?"); } else { PopUpText.fillPopUp("Já utilizou todas as ajudas!"); } }
private void Die(Character self) { //TODO: remove listeners OnDamage.RemoveAllListeners(); if (this as Goblin) { (this as Goblin).particles.Stop(); } (this as Goblin)?.Speak(SoundBank.GoblinSound.Death); if (MovementAudio) { MovementAudio.Stop(); } State = CharacterState.Dead; HealtBar.gameObject.SetActive(false); if (tag == "Player") { PopUpText.ShowText(name + " is dead"); } //LOOT CREATIONS var loot = gameObject.AddComponent <Lootable>(); loot.ContainsLoot = false; if (CharacterRace != Race.Goblin) { loot.ContainsFood = true; loot.Food = CharacterRace + " " + NameGenerator.GetFoodName(); } var removeEquip = Equipped.Values.Where(e => e).ToArray(); foreach (var eq in removeEquip) { RemoveEquipment(eq); loot.EquipmentLoot.Add(eq); eq.transform.parent = loot.transform.parent; } InArea.Lootables.Add(loot); //TODO: check if this create problems: navMeshAgent.enabled = false; }
public void DoError(ErrorIndex errorIndex, string Message = "", Action callbackClosePopUpError = null) { Debug.LogError(errorIndex); Loading.Instance.ExitLoading(); PopUpText _PopUpError = PopUp.Instance.ShowPopUp <PopUpText>(PopUpName.PopUpText); if (Message != "" && Message != null) { _PopUpError.SetMes(Message, () => { if (callbackClosePopUpError != null) { callbackClosePopUpError(); } }); return; } switch (errorIndex) { case ErrorIndex.ErrorLoginFail: Message = "Have error while login , please check again your username and password"; break; case ErrorIndex.ErrorNetwork: Message = "Error. Check internet connection!"; break; case ErrorIndex.ErrorAuthentication: Message = "An authentication error has occurred"; break; case ErrorIndex.ErrorCantBeBlank: Message = "Error.Can't Be Blank!"; break; case ErrorIndex.ErrorInvalidEmail: Message = "Error.Invalid email!"; break; case ErrorIndex.PasswordsNotMatch: Message = "Error.Password do not match!"; break; } Debug.LogError(Message); _PopUpError.SetMes(Message, () => { if (callbackClosePopUpError != null) { callbackClosePopUpError(); } }); }
public static void Initialize() { canvas = GameObject.Find("Canvas"); popUpText = Resources.Load <PopUpText>("PopUpText/PopUpTextParent"); damageText = Resources.Load <PopUpText>("PopUpText/DamageTextParent"); foreach (Camera c in Camera.allCameras) { if (c.gameObject.name == "Bee Camera") { camera = c; } } }
void Start() { waveManager = GameObject.Find("GameManager").GetComponent <WaveManager> (); scoreManager = GameObject.Find("GameManager").GetComponent <ScoreManager> (); currencyManager = GameObject.Find("GameManager").GetComponent <CurrencyManager> (); popuptext = GameObject.Find("GameManager").GetComponent <PopUpText> (); playerEntity = GameObject.Find("Player").GetComponent <LivingEntity> (); gameModeManager = GameObject.Find("GameManager").GetComponent <GameModeManager> (); unit = GetComponent <Unit> (); drops = GetComponent <Drops>(); livingEntity = GetComponent <LivingEntity> (); livingEntity.deathEvent += OnDeath; }
private void DefautOnError(string error) { if (isShowPopUp) { PopUpText popup = PopUp.Instance.ShowPopUp <PopUpText>(PopUpName.PopUpText); popup.SetMes(error); } if (onError != null) { onError(error); return; } Debug.LogError("onError " + error); }
private void NextLevel() { //a sound SoundController.PlayLevelup(); PopUpText.ShowText(name + " has gained a new level!"); //TODO: health should be handled differently than other stuff HEA.LevelUp(); if (CurrentLevel == 2) { WaitingOnClassSelection = true; } GoblinUIList.UpdateGoblinList(); }
/// <summary> /// 显示 /// </summary> private void showText() { if (count == 0) { if (textList.Count == 0) { EnterFrame.instance.removeEnterFrame(showText); } else { GameObject prefab = AssetsManager.instance.getMainUIPrefab("popuptext") as GameObject; GameObject go = GameObject.Instantiate(prefab); RectTransform rectTF = go.transform as RectTransform; rectTF.SetParent(UIManager.instance.getUILayer(UILayer.PopUpLayer), false); PopUpText popUpText = new PopUpText(); popUpText.init(go); popUpText.txt.text = textList[0]; textList.RemoveAt(0); } } count = count > 100 ? 0 : count + 1; }
IEnumerator WaitPopUp() { yield return(new WaitForSeconds(3f)); PopUpText.fillPopUp(""); }
private void SelectAction() { switch (State) { case CharacterState.Idling: //reset morale Morale = COU.GetStatMax() * 2; if (actionInProgress) { if (navMeshAgent.remainingDistance < 0.02f) { actionInProgress = false; } } else if (IrritationMeter >= IrritaionTolerance) { ChangeState(CharacterState.Attacking); } else if (Random.value < 0.015f) //selecting idle action { (this as Goblin)?.Speak(PlayerController.GetDynamicReactions(PlayerController.DynamicState.Idle)); actionInProgress = true; Vector3 dest; if (InArea) { if (GetClosestEnemy() && ( //ANY friends fighting InArea.PresentCharacters.Any(c => c.tag == tag && c.Alive() && c.Attacking()) // I am aggressive wanderer || (StickToRoad && InArea.PresentCharacters.Any(c => c.tag == "Player" & !c.Hiding())) )) { //Debug.Log(name + ": Joining attack without beeing attacked"); ChangeState(CharacterState.Attacking, true); Morale -= 5; Target = GetClosestEnemy().transform.position; dest = Target; } else if ((this as Goblin) && Team && Team.Leader.InArea != InArea && Team.Leader.Idling()) { dest = Team.Leader.InArea.GetRandomPosInArea(); } else if ((this as Goblin) && tag == "Player" && GetClosestEnemy() && (GetClosestEnemy().transform.position - transform.position).magnitude < provokeDistance) { ChangeState(CharacterState.Provoking, true); var ctx = GetClosestEnemy(); (this as Goblin).ProvokeTarget = ctx; (this as Goblin)?.Speak(PlayerController.GetDynamicReactions(PlayerController.DynamicState.Mocking)); dest = ctx.transform.position; } else if (StickToRoad) { var goingTo = InArea.GetClosestNeighbour(transform.position, true); dest = goingTo.PointOfInterest ? goingTo.GetRandomPosInArea(): goingTo.transform.position; //Debug.Log(name + ": Wandering to "+ goingTo); Target = dest; goingTo.PresentCharacters.ForEach(c => StartCoroutine(c.SpotArrivalCheck(this))); ChangeState(CharacterState.Travelling, true); } else { dest = InArea.GetRandomPosInArea(); } } else { dest = transform.position + Random.insideUnitSphere * idleDistance; dest.y = 0; } navMeshAgent.SetDestination(dest); //new Vector3(Random.Range(-idleDistance, idleDistance), 0,Random.Range(-idleDistance, idleDistance))); } //TODO: use a different method for activity selection than else if else if (Random.value < 0.0025f && this as Goblin && Team && !(Team.Leader == this) && (this as Goblin).ClassType > Goblin.Class.Slave & !Team.Challenger && (Team.Leader as Goblin).CurrentLevel < ((Goblin)this).CurrentLevel) { //TODO: make it only appear after a while Debug.Log("Chief Fight!!"); Team.ChallengeForLeadership(this as Goblin); } //TODO: define better which characters should search stuff else if (Random.value < 0.001f * SMA.GetStatMax() && Team && this as Goblin && !InArea.AnyEnemies() && InArea.Lootables.Any(l => !l.Searched)) { var loots = InArea.Lootables.Where(l => !l.Searched).ToArray(); var loot = loots[Random.Range(0, loots.Count())]; (this as Goblin).Search(loot); } break; case CharacterState.Attacking: if (AttackTarget && AttackTarget.Alive() && AttackTarget.InArea == InArea) { if (AttackTarget.Fleeing()) { var c = GetClosestEnemy(); if (c) { AttackTarget = c; } } navMeshAgent.SetDestination(AttackTarget.transform.position); //TODO: add random factor } else { TargetGone(); } break; case CharacterState.Travelling: navMeshAgent.SetDestination(Target); //check for arrival and stop travelling if (Vector3.Distance(transform.position, Target) < 3f) { //Debug.Log(name +" arrived at target"); State = CharacterState.Idling; actionInProgress = false; break; } break; case CharacterState.Fleeing: (this as Goblin)?.Speak(SoundBank.GoblinSound.PanicScream); //if (actionInProgress &! navMeshAgent.hasPath) //{ // //TODO: move into next if statement, if correct // Debug.Log("stuck fleeing resolved"); // actionInProgress = false; // ChangeState(CharacterState.Idling, true); //} if (fleeingToArea == InArea && navMeshAgent.remainingDistance < 0.1f) { actionInProgress = false; ChangeState(CharacterState.Idling, true); } else if (!actionInProgress) { fleeingToArea = InArea.GetClosestNeighbour(transform.position, StickToRoad); navMeshAgent.SetDestination(fleeingToArea.GetRandomPosInArea()); actionInProgress = true; } break; case CharacterState.Dead: break; case CharacterState.Hiding: if (!Hidingplace) { State = CharacterState.Idling; } //already set the destination if ((navMeshAgent.destination - hiding.HideLocation.transform.position).sqrMagnitude < 1f) { if (InArea.AnyEnemies() && navMeshAgent.remainingDistance > 0.2f) { ChangeState(CharacterState.Idling); } } else { navMeshAgent.SetDestination(hiding.HideLocation.transform.position); } break; //Only to be used for chief fights. TODO: rename case CharacterState.Watching: if (!Team || !Team.Challenger) { //cheer (this as Goblin)?.Speak(SoundBank.GoblinSound.Laugh); ChangeState(CharacterState.Idling, true); } else { if (Vector3.Distance(transform.position, Team.Challenger.transform.position) < 3f && Team.Challenger != this && Team.Leader != this) { //cheer (this as Goblin)?.Speak(PlayerController.GetDynamicReactions(PlayerController.DynamicState.ChiefBattleCheer)); navMeshAgent.ResetPath(); } else if (!actionInProgress) { navMeshAgent.SetDestination(Team.Challenger.transform.position); actionInProgress = true; } } break; case CharacterState.Searching: //check for arrival and stop travelling if (Vector3.Distance(transform.position, LootTarget.transform.position) < 2f) { if (LootTarget.ContainsLoot) { (this as Goblin)?.Speak(SoundBank.GoblinSound.Laugh); PopUpText.ShowText(name + " found " + LootTarget.Loot); Team.OnTreasureFound.Invoke(1); } if (LootTarget.ContainsFood) { (this as Goblin)?.Speak(SoundBank.GoblinSound.Laugh); PopUpText.ShowText(name + " found " + LootTarget.Food); Team.OnFoodFound.Invoke(5); } if (this as Goblin) { foreach (var equipment in LootTarget.EquipmentLoot) { //TODO: create player choice for selecting goblin (this as Goblin)?.Speak(SoundBank.GoblinSound.Laugh); PopUpText.ShowText(name + " found " + equipment.name); if (Team && Team.Members.Count > 1) { Team.OnEquipmentFound.Invoke(equipment, this as Goblin); } else { Equip(equipment); } } } LootTarget.EquipmentLoot.Clear(); LootTarget.ContainsFood = false; LootTarget.ContainsLoot = false; LootTarget.Searched = true; State = CharacterState.Idling; break; } break; case CharacterState.Provoking: var g = this as Goblin; if (!g) { Debug.LogWarning("Non-goblin is being provocative"); break; } if (!g.ProvokeTarget || g.ProvokeTarget.InArea != InArea) { (this as Goblin)?.Speak(SoundBank.GoblinSound.Laugh); g.ProvokeTarget = GetClosestEnemy(); } if (!g.ProvokeTarget) { ChangeState(CharacterState.Idling, true); break; } if (g.ProvokeTarget.Attacking()) { ChangeState(CharacterState.Attacking); break; } if (!actionInProgress && navMeshAgent.remainingDistance < 0.5f) { actionInProgress = true; navMeshAgent.SetDestination(g.ProvokeTarget.transform.position); ProvokeStartTime = Time.time; break; } if (ProvokeTime + ProvokeStartTime > Time.time) { //run away actionInProgress = false; var dest = InArea.GetRandomPosInArea(); navMeshAgent.SetDestination(dest); g.ProvokeTarget.IrritationMeter++; break; } if ((g.ProvokeTarget.transform.position - transform.position).magnitude < 4) //Provoke { navMeshAgent.isStopped = true; if (Random.value < 0.2f) { (this as Goblin)?.Speak( PlayerController.GetDynamicReactions(PlayerController.DynamicState.Mocking)); } } break; case CharacterState.Surprised: navMeshAgent.isStopped = true; if (SurprisedTime + SurprisedStartTime <= Time.time) { ChangeState(CharacterState.Attacking); } break; case CharacterState.Resting: if (!Team || !Team.Campfire) { ChangeState(CharacterState.Idling, true); } else { if (Vector3.Distance(transform.position, Team.Campfire.transform.position) < 4f) { (this as Goblin)?.Speak(SoundBank.GoblinSound.Eat); navMeshAgent.ResetPath(); } else if (!actionInProgress) { navMeshAgent.SetDestination(Team.Campfire.transform.position); actionInProgress = true; } } break; default: break; } }