// Called by other scripts to hit the player public void GetHit(Vector3 knockback, float knockbackAmt) { health--; velocity -= knockback * knockbackAmt; velocity = Vector3.ClampMagnitude(velocity, maxSpeed); GetComponent <SpriteRenderer>().color = Color.red; if (health <= 0) { if (attackGO != null) { Destroy(attackGO); } if (tempAttackGO != null) { Destroy(tempAttackGO); } playerScript.AddGold(Random.Range(1, 5)); waveManager.DestroyEnemy(this.gameObject); Destroy(gameObject); } }
public override float Affect(Message message, float input) { PlayerScript player = null == message ? null : message.Player(myObject); if (null == player) { } else { switch (myResource) { case Enum.ManaCap: player.AddManaCap((int)myValue); break; case Enum.Debt: player.AddDebt((int)myValue); break; case Enum.Gold: player.AddGold((int)myValue); break; case Enum.Mana: player.AddMana((int)myValue); break; case Enum.Overload: player.AddOverload((int)myValue); break; } } return(input); }
private void Update() { bool active = false; for (int i = 0; i < items.Count; i++) { if (helper.getDistance(player.transform.position, itemObjs[i].transform.position) < Constants.TRADER_ITEMUI_ACTIVE_DISTANCE) { active = true; itemUI.SetUIData(items[i]); itemUI.ShowUI(true); bool canBuy = playerScript.HasGold(items[i].cost); itemUI.SetCostCanBuy(canBuy); if (Input.GetKeyDown(KeyCode.E) && canBuy) { if (items[i].modifier != null) { playerScript.AddModifier(items[i]); } else if (items[i].item != null) { playerScript.AddItem(items[i].item); } playerScript.AddGold(-items[i].cost); Destroy(itemObjs[i]); itemObjs.RemoveAt(i); items.RemoveAt(i); } } } if (!active) { itemUI.ShowUI(false); } }