public void SpawnDamageNumbers(int amount, Color colour, Vector3 position) { DamageNumbers numbers = Instantiate(damageNumbersPrefab); numbers.transform.position = position; numbers.Init(amount, colour); }
/// <summary> /// Takes the damage given it and updates slider and text /// </summary> /// <param name="amount">Amount.</param> public void TakeDamage(int amount) { gameObject.AddComponent <DamageNumbers>(); DamageNumbers damageNumbers = gameObject.GetComponent <DamageNumbers> (); damageNumbers.prefabDamage = (GameObject)Resources.Load("Damage", typeof(GameObject)); damageNumbers.CreateDamagePopup(amount, transform.position); // Set the damaged flag so the screen will flash. damaged = true; // Reduce the current health by the damage amount. currentHealth -= amount; if (currentHealth <= 0) { currentHealth = 0; } // Set the health bar's value to the current health. healthSlider.value = currentHealth; healthField.text = "<color='yellow'>" + currentHealth + "</color><color='white'> / " + maxHealth + "</color>"; // Play the hurt sound effect. //playerAudio.Play (); // If the player has lost all it's health and the death flag hasn't been set yet... if (currentHealth <= 0 && !isDead) { // ... it should die. Death(); } }
public static void Initialize() { canvas = GameObject.Find("DamageCanvas"); if (damageText == null) { damageText = Resources.Load <DamageNumbers>("Prefabs/edmgParent"); } }
public static void CreateDamageText(string text, Transform location) { DamageNumbers instance = Instantiate(damageText); instance.transform.SetParent(canvas.transform, false); instance.transform.position = new Vector2(location.position.x + Random.Range(-0.1f, 0.1f), location.position.y + Random.Range(0.1f, 0.3f)); instance.SetText(text); }
public static void CreateFloatingText(string text, Transform location) { DamageNumbers instance = Instantiate(popupText); Vector2 screenPostion = Camera.main.WorldToScreenPoint(location.position); instance.transform.SetParent(canvas.transform, false); instance.transform.position = screenPostion; instance.SetText(text); }
public static void initialize() { canvas = GameObject.Find("UI"); if (!popupText) { popupText = Resources.Load <DamageNumbers>("Prefabs/PopupTextParent"); } }
private void Awake() { nextFireTime = timeUntilFire; rb2d = GetComponent <Rigidbody2D>(); spriteRenderer = GetComponent <SpriteRenderer>(); spriteAnimator = GetComponent <SpriteAnimator>(); bulletCounter = GameObject.FindGameObjectWithTag("BulletManager").GetComponent <BulletCounter>(); playerController = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerController>(); playerAudioManager = GameObject.FindGameObjectWithTag("PlayerAudio").GetComponent <ObjectAudioManager>(); damageNumbers = GameObject.FindGameObjectWithTag("DamageNumbers").GetComponent <DamageNumbers>(); }
public static void ResolveTriggers(TriggerTypes triggerType, Action callBack = null) { if (callBack != null) { Console.Write(triggerType.ToString(), LogTypes.Triggers, true, "yellow"); } else { Console.Write(triggerType + " is resolved again", LogTypes.Triggers, false, "yellow"); } if (triggerType == TriggerTypes.OnDamageIsDealt && callBack != null) { DamageNumbers.UpdateSavedHP(); } StackLevel currentLevel = GetCurrentLevel(); if (currentLevel == null || currentLevel.IsActive) { CreateNewLevelOfStack(triggerType, callBack); currentLevel = GetCurrentLevel(); } if (!currentLevel.IsActive) { SetStackLevelCallBack(callBack); List <Trigger> currentTriggersList = currentLevel.GetTriggersByPlayer(Phases.PlayerWithInitiative); Players.PlayerNo currentPlayer = (currentTriggersList.Count > 0) ? Phases.PlayerWithInitiative : Roster.AnotherPlayer(Phases.PlayerWithInitiative); currentTriggersList = currentLevel.GetTriggersByPlayer(currentPlayer); if (currentTriggersList.Count != 0) { currentLevel.IsActive = true; if ((currentTriggersList.Count == 1) || (IsAllSkippable(currentTriggersList))) { FireTrigger(currentTriggersList[0]); } else { RunDecisionSubPhase(); } } else { if (triggerType == TriggerTypes.OnDamageIsDealt) { DamageNumbers.ShowChangedHP(); } DoCallBack(); } } }
private void Start() { playerController = PlayerController.current; playerAudioManager = PlayerController.playerAudioManager; damageNumbers = FindObjectOfType <DamageNumbers>(); bulletCounter = FindObjectOfType <BulletCounter>(); if (affectedByForce) { forceScript = gameObject.AddComponent <EnemyGetAffectedByForce>() as EnemyGetAffectedByForce; } }
public void MakeDamageNumbers(int iDamage, DamageNumbers prefab) { DamageNumbers dn = Instantiate <DamageNumbers>(prefab); dn.transform.position = transform.position + new Vector3(0.0f, minion.template.fHeight, 0.0f); dn.Init(iDamage); if (baseNumbers != null) { baseNumbers.Bump(); dn.nextNumbers = baseNumbers; } baseNumbers = dn; }
public static void ResolveTriggers(TriggerTypes triggerType, Action callBack = null) { if (DebugManager.DebugTriggers) { Debug.Log("Triggers are resolved: " + triggerType); } if (triggerType == TriggerTypes.OnDamageIsDealt && callBack != null) { DamageNumbers.UpdateSavedHP(); } StackLevel currentLevel = GetCurrentLevel(); if (currentLevel == null || currentLevel.IsActive) { CreateNewLevelOfStack(callBack); currentLevel = GetCurrentLevel(); } if (!currentLevel.IsActive) { SetStackLevelCallBack(callBack); List <Trigger> currentTriggersList = currentLevel.GetTriggersByPlayer(Phases.PlayerWithInitiative); Players.PlayerNo currentPlayer = (currentTriggersList.Count > 0) ? Phases.PlayerWithInitiative : Roster.AnotherPlayer(Phases.PlayerWithInitiative); currentTriggersList = currentLevel.GetTriggersByPlayer(currentPlayer); if (currentTriggersList.Count != 0) { currentLevel.IsActive = true; if ((currentTriggersList.Count == 1) || (IsAllSkippable(currentTriggersList))) { FireTrigger(currentTriggersList[0]); } else { RunDecisionSubPhase(); } } else { if (triggerType == TriggerTypes.OnDamageIsDealt) { DamageNumbers.ShowChangedHP(); } DoCallBack(); } } }
/// <summary> /// Takes the damage given it and updates slider and text /// </summary> /// <param name="amount">Amount.</param> public IEnumerator TakeDamage(int amount) { DamageNumbers damageNumbers = gameObject.AddComponent <DamageNumbers>(); damageNumbers.battleCanvas = GameObject.Find("GameBoyCanvas").GetComponent <RectTransform>(); damageNumbers.prefabDamage = prefabDamage; damageNumbers.CreateDamagePopup(amount, transform.position); ShakeCamera(); // Set the damaged flag so the screen will flash. //damaged = true; // Reduce the current health by the damage amount. losingHealthCurrent = currentHealth; currentHealth -= amount; damaged = true; damageDealt = amount; while (damageDealt > 0) { yield return(null); } damaged = false; if (currentHealth <= 0) { currentHealth = 0; } UpdateHealth(); // Set the health bar's value to the current health. //healthSlider.value = currentHealth; //healthField.text = "<color='yellow'>" + currentHealth + "</color><color='white'> / " + maxHealth + "</color>"; // Play the hurt sound effect. //playerAudio.Play (); // If the player has lost all it's health and the death flag hasn't been set yet... if (currentHealth <= 0 && !isDead) { // ... it should die. Death(); } underAttack = false; }
public static DamageNumber CreateFromPrefab(DamageNumber prefab, int amount, Vector3 pos, DamageNumbers parent) { var number = Instantiate(prefab); pos.x += Random.Range(-JITTER_X, JITTER_X); number.GetComponent<Text>().text = amount.ToString(); number.spawned = Time.time; number.transform.SetParent(parent.transform, false); number.transform.position = pos; return number; }
void Start() { LeanTween.init(1000); itemTemplates = FindObjectOfType <ItemTemplates>(); inventory = GetComponent <Inventory>(); artifacts = GetComponent <Artifacts>(); rigidBody2D = GetComponent <Rigidbody2D>(); spriteRenderer = GetComponent <SpriteRenderer>(); hullUpgradeManager = GetComponent <HullUpgradeManager>(); redBarImage = healthBarFill.GetComponentsInChildren <Image>()[1]; redBarImage.enabled = false; PlayerProperties.spriteRenderer = this.spriteRenderer; if (SceneManager.GetActiveScene().name != "Tutorial" && SceneManager.GetActiveScene().name != "Demo Level") { if (!playerHubNames.Contains(SceneManager.GetActiveScene().name)) { loadPrevItems(); isInPlayerHub = false; } else { isInPlayerHub = true; } } damageNumbers = FindObjectOfType <DamageNumbers>(); audioManager = FindObjectOfType <AudioManager>(); healNumbers = FindObjectOfType <PlayerHealNumbers>(); cameraShake = FindObjectOfType <CameraShake>(); artifacts.artifactsUI.SetActive(false); inventory.inventory.SetActive(false); if (SceneManager.GetActiveScene().name != "Tutorial") { shipHealth = shipHealthMAX; } CheckAndUpdateHealth(); }
public static void CreateDamage(GameObject enemy, int damage) { if (enemy.GetComponent <EnemyController>().health <= 0) { return; } GameObject[] numbers = GameObject.FindGameObjectsWithTag("DamageNumber"); for (int i = 0; i < numbers.Length; i++) { DamageNumbers currentNumber = numbers[i].GetComponent <DamageNumbers>(); if (currentNumber.enemy == enemy) { currentNumber.AddDamage(damage); return; } } GameObject numberObj = Instantiate(DamageNumberManager.damagePrefab, GameManager.Canvas); DamageNumbers number = numberObj.GetComponent <DamageNumbers>(); number.enemy = enemy.gameObject; number.AddDamage(damage); }
public void SetUp() { m_isDefending = false; oldPos = gameObject.transform.position; newPos = gameObject.transform.position; m_battleSystem = FindObjectOfType <BattleSystem>(); r_damageNumbers = GetComponentInChildren <DamageNumbers>(); if (gameObject.tag == "Player") { CharacterSheet stats = r_characterSheet; m_spriteR = stats.m_spriteR; m_spriteL = stats.m_spriteL; GetComponent <SpriteRenderer>().sprite = m_spriteL; m_facingLeft = true; m_level = stats.m_level; m_name = stats.name; m_maxHP = stats.m_maxHP; m_HP = stats.m_currentHP; m_maxSP = stats.m_maxSP; m_SP = stats.m_currentSP; m_maxAP = stats.m_maxAP; m_AP = stats.m_currentAP; m_attack = stats.m_strength; m_defence = stats.m_fortitude; m_magic = stats.m_wisdom; m_magicDefence = stats.m_resistance; m_speed = stats.m_agility; m_x = stats.m_x; m_y = stats.m_y; } if (gameObject.tag == "Enemy") { EnemySheet stats = r_enemySheet; m_spriteR = stats.m_spriteR; m_spriteL = stats.m_spriteL; GetComponent <SpriteRenderer>().sprite = m_spriteR; m_facingLeft = false; m_level = stats.m_level; m_maxHP = stats.m_maxHP; m_HP = stats.m_HP; m_maxSP = stats.m_maxSP; m_SP = stats.m_SP; m_maxAP = stats.m_maxAP; m_AP = stats.m_AP; m_attack = stats.m_attack; m_defence = stats.m_defence; m_magic = stats.m_magic; m_magicDefence = stats.m_magicDefence; m_speed = stats.m_speed; foreach (BattlePawn pawn in m_battleSystem.m_charactersInBattle) { if (pawn.gameObject.tag == "Player") { r_playerPawns.Add(pawn); } } r_targetPlayer = r_playerPawns[0]; } }
void Start() { dmg = gameObject.GetComponentInParent(typeof(DamageNumbers)) as DamageNumbers; text = GetComponent <Text>(); }