/// <summary> /// Convenience function for adding new SCT entries. /// </summary> public static void Print(GameObject go, string text, Color color) { ScrollingCombatText sct = go.GetComponent <ScrollingCombatText>(); if (sct == null) { sct = go.AddComponent <ScrollingCombatText>(); sct.style = Config.Instance.infoStyle; } sct.Add(text, color); }
/// <summary> /// Dock the ship at the specified town. /// </summary> void DockShip(Town town) { int gold = SellCargo(town); if (gold > 0) { mCurrentRevenue += gold; Config.Instance.gold += gold; ScrollingCombatText.Print(gameObject, "$" + gold, (gold < prefab.price / 10) ? Color.yellow : Color.green); } LoadCargo(town); mStartTime = Time.time + 2f; mLastTown = town; }
public void TakeDamage(int value, bool isCrit) { if (healthbar == null) { healthbar = FindObjectOfType <GameVariables>().CreateHealthbar(this.gameObject); } ScrollingCombatText battleText = Instantiate(scrollingBattleText).GetComponent <ScrollingCombatText>(); battleText.Create(gameObject.transform, value.ToString(), isCrit); currentHealth -= value; if (currentHealth <= 0) { Die(); } }
/// <summary> /// React to the ship being hit by cannon fire. /// </summary> void OnCollisionEnter(Collision col) { Cannonball cb = col.collider.GetComponent <Cannonball>(); if (cb != null && cb.damage > 0f) { // Damage the hull float damage = mStats.ApplyDamage(cb.damage, cb.owner); // Print the damage text over the hull if (damage > 0f) { ScrollingCombatText.Print(gameObject, "-" + Mathf.RoundToInt(damage), Color.red); } } }
/// <summary> /// Damage the sail when hit by a cannonball. /// </summary> void OnTriggerEnter(Collider col) { Cannonball cb = col.GetComponent <Cannonball>(); if (cb != null && cb.damage > 0f) { // Damage the sails float damage = mStats.ApplyDamageToSails(cb.damage); // Print the damage text over the sail if (damage > 0f) { ScrollingCombatText.Print(gameObject, "-" + Mathf.RoundToInt(damage), new Color(1f, .4f, 0f)); } } }
/// <summary> /// Show a useful tooltip regarding the ship's weekly income. /// </summary> void OnMouseEnter() { int profit = mLastRevenue - mLastUpkeep; if (profit == 0) { profit = mCurrentRevenue - mCurrentUpkeep; } if (profit < 0) { ScrollingCombatText.Print(gameObject, "Weekly Loss: $" + profit, Color.red); } else { ScrollingCombatText.Print(gameObject, "Weekly Profit: $" + profit, (profit < prefab.price / 10) ? Color.yellow : Color.green); } }
public void Spawn(Vector3 position, string text, float duration) { ScrollingCombatText instance = Instantiate(Prefab, position, Quaternion.identity); instance.Initialize(text, duration, Color, TargetRelativeOffset); }