protected override void EnemyFSMSrart() { Player = GameObject.FindGameObjectWithTag("Player"); anim = GetComponent <Animator> (); rigi2d = GetComponent <Rigidbody2D> (); heath = GetComponent <Heath> (); }
void LoadAttribute(int ID) { try { EnemyStat stat = new EnemyStat(); stat = EnemyManager.instance.GetEnemyAttribute(ID); if (stat != null) { Name = stat.Name; Heath.Value = stat.Heath.Value; Heath.AddModifier(stat.Heath.Value * stat.Level); CurrentHeath = Heath.GetValue(); Damage.Value = stat.Damage.Value; Damage.AddModifier(stat.Damage.Value * stat.Level); Defense.Value = stat.Defense.Value; Defense.AddModifier(stat.Defense.Value * stat.Level); Crit.Value = stat.Crit.Value; if (IsRetransform) { transform.parent.transform.position = stat.Position; transform.parent.transform.rotation = Quaternion.Euler(stat.Rotation); transform.parent.transform.localScale = stat.Scale; } } } catch (Exception ex) { Logs.LogE("Can't load emeny ID " + ID + " : " + ex.ToString()); } }
public void takeDamage(float damage, bool isCrit) { if (!isCrit) { Heath currentHeath = GetComponent <Heath>(); currentHeath.reduceHeath(damage); GameObject newText = Instantiate(damageText, transform.position, transform.rotation) as GameObject; newText.GetComponent <FloatingText>().text = "-" + damage.ToString(); newText.GetComponent <FloatingText>().currentColor = new Color(255, 255, 255); } }
// Start is called before the first frame update void Start() { currentHeath = GetComponent <Heath>(); currentArmor = GetComponent <Armor>(); controller = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameController> (); playerBody = GetComponent <Rigidbody>(); cameraPos = Camera.main.gameObject.transform; currentWeapon = weaponObject.GetComponent <Weapon>(); //animator = GetComponent<Animator>(); inAttackAnimation = false; attackCount = 0; }
public void attack() { inAttackAnimation = false; Collider[] hitColliders = Physics.OverlapSphere(transform.position + (transform.forward * 2), currentWeapon.reach); for (int i = 0; i < hitColliders.Length; i++) { Debug.Log(hitColliders[i].gameObject.tag); if (hitColliders[i].gameObject.CompareTag("Enemy")) { GameObject other = hitColliders[i].gameObject; other.GetComponent <Rigidbody>().AddForce((transform.position - other.transform.position).normalized * 16); Enemy enemy = hitColliders[i].gameObject.GetComponent <Enemy>(); Heath enemyHeath = hitColliders[i].gameObject.GetComponent <Heath>(); if (attackCount == 0) { enemy.takeDamage(Mathf.RoundToInt(Random.Range(currentWeapon.damage - 2, currentWeapon.damage + 2)), false); } else if (attackCount == 1) { enemy.takeDamage(Mathf.RoundToInt(Random.Range(currentWeapon.damage - 1, currentWeapon.damage + 5)), false); } //enemyHeath.reduceHeath(currentWeapon.damage); Debug.Log(enemyHeath.getHitPoints()); } } if (attackCount == 0) { attackCount = 1; } else if (attackCount == 1) { attackCount = 0; } }
private void OnGUI() { if (DebugManager.instance.isDebug()) { Vector2 size = new Vector2(120, 20); Vector3 pos = Camera.main.WorldToScreenPoint(HeathBar.position); pos.y = Screen.height - pos.y; GUI.Box(new Rect(pos.x - size.x / 2, pos.y, size.x, size.y), CurrentHeath + "/" + Heath.GetValue()); GUI.enabled = true; } }