public override bool Cast() { bool wasCast = false; effectAlpha = 1f; Vector2 mousePosition = player.GetComponent <ClickHandler>().getMousePosition(); Vector2 playerPosition = player.GetComponent <Rigidbody2D>().position; RaycastHit2D[] hits = Physics2D.LinecastAll(playerPosition, mousePosition); foreach (RaycastHit2D hit in hits) { if (hit != null && hit.collider != null) { if (hit.collider.gameObject.GetComponent <EnemyController>() != null) { // CombatText combatText = hit.collider.gameObject.AddComponent(typeof(CombatText)) as CombatText; // combatText.text= damage.ToString(); CombatText.Create(hit.collider.gameObject.transform.position, 100.ToString(), false); StatusText.Create(hit.collider.gameObject.transform.position, "Stunned", false); hit.collider.gameObject.GetComponent <CombatTextFactory>().addCombatText("Hit Enemy with dash"); Debug.Log("Hit Enemy with dash"); } } } player.GetComponent <Rigidbody2D>().position = mousePosition; DashEffect.Create(playerPosition, mousePosition); wasCast = true; Debug.Log("Cast Dash"); return(wasCast); }
public override bool Cast() { bool wasCast = false; SpinAttackEffect.Create(radius); effectAlpha = 1f; Vector2 playerPosition = player.GetComponent <Rigidbody2D>().position; RaycastHit2D[] hits = Physics2D.CircleCastAll(playerPosition, radius, playerPosition); foreach (RaycastHit2D hit in hits) { if (hit != null && hit.collider != null) { if (hit.collider.gameObject.GetComponent <EnemyController>() != null) { // CombatText combatText = hit.collider.gameObject.AddComponent(typeof(CombatText)) as CombatText; // combatText.text= damage.ToString(); CombatText.Create(hit.collider.gameObject.transform.position, 100.ToString(), false); hit.collider.gameObject.GetComponent <CombatTextFactory>().addCombatText("Hit Enemy with spin"); Debug.Log("Hit Enemy with spin"); } } } wasCast = true; Debug.Log("Cast SpinAttack"); return(wasCast); }
public void TakeDamage(int damage) { damage = Mathf.Clamp(damage, 0, int.MaxValue); // Damage should never be negative. // Calculate damage modifiers bool isCriticalHit = UnityEngine.Random.Range(0, 100) < 30; int damageTotal = UnityEngine.Random.Range(1, damage); if (isCriticalHit) { damageTotal *= 2; } healthSystem.Damage(damageTotal); OnHealthChanged?.Invoke(); Debug.Log($"{charName} take {damageTotal} points of damage."); CombatText.Create(GetPosition() + new Vector3(0, .5f, .5f), damageTotal, isCriticalHit, new Color32(255, 128, 0, 255)); if (healthSystem.GetHealth() <= 0) { Die(); } }
public void Setup(GameObject target) { this.target = target; CombatText.Create(target.transform.position, "10", false); if (audioSource.isPlaying) { audioSource.Stop(); } audioSource.PlayOneShot(audioSource.clip, 1); }
private void AddHealth(int healing) { healthSystem.Heal(healing); OnHealthChanged?.Invoke(); Debug.Log($"{charName} heals for {healing}."); CombatText.Create(GetPosition() + new Vector3(0, .5f, .5f), 5, false, Color.green); if (currentHP >= maxHP) { currentHP = maxHP; } }
void applyDOT() { DOTTimer -= Time.deltaTime; effectDurationTimer -= Time.deltaTime; if (DOTTimer <= 0) { DOTTimer = 3f; CombatText.Create(target.transform.position, "10", false); } if (effectDurationTimer <= 0) { Destroy(gameObject); } }