public override void LogicUpdate() { if (currentTime < timeWait) { if (NextStateTrigger()) { Exit(); return; } Collider2D[] colliders = Physics2D.OverlapCircleAll(AttackZone.position, AttackRadius, AttackHit.hitLayer); foreach (Collider2D coll in colliders) { Damageable target = coll.GetComponent <Damageable>(); if (target != null && !hittingTargets.Contains(target)) { Fight2D.Action(AttackHit, target); hittingTargets.Add(target); } } currentTime += Time.deltaTime; } else { Exit(); } }
public void AlertObservers(string message) { if (message.Equals("AttackAnimationEnded")) { switch (this.fightMode) { case FightMode.Punch: Fight2D.Action(this.Punch.position, this.PunchRadius, this.activeLayersToInteraction, false, this.Character.PunchDamage, this.Character.PunchImpulse * this.impulseDirection); break; case FightMode.Kick: Fight2D.Action(this.Kick.position, this.KickRadius, this.activeLayersToInteraction, false, this.Character.KickDamage, this.Character.KickImpulse * this.impulseDirection); break; default: break; } this.fightMode = FightMode.None; } if (message.Equals("PunchHappened")) { MessageBroker.Default.Publish(new PunchHappened()); } if (message.Equals("KickHappened")) { MessageBroker.Default.Publish(new KickHappened()); } }
private IEnumerator attack() { float currentTime = 0; animator.SetTrigger("Attack"); canAttack = false; for (; currentTime < delay; currentTime += Time.deltaTime) { yield return(null); } Collider2D[] colliders = Physics2D.OverlapCircleAll(model.transform.position, attackRadius, model.hitLayer); foreach (Collider2D c in colliders) { Damageable target = c.GetComponent <Damageable>(); if (target != null && !target.isImmunuted) { Fight2D.Action(model, target); } } for (; currentTime < period; currentTime += Time.deltaTime) { yield return(null); } canAttack = true; }
private IEnumerator action() { float currentTime = 0; beginAttack?.Invoke(); animator.SetTrigger("stroke"); for (; currentTime < delay; currentTime += Time.deltaTime) { yield return(null); } Vector2 position = transform.position; Vector2 currentOffset = offset; currentOffset.x *= Mathf.Sign(transform.localScale.x); Collider2D[] colliders = Physics2D.OverlapCircleAll(position + currentOffset, attackRadius, model.hitLayer); foreach (Collider2D c in colliders) { Damageable target = c.GetComponent <Damageable>(); if (target != null && !target.isImmunuted && !passes.Contains(target)) { Fight2D.Action(model, target); passes.Add(target); } } passes.Clear(); while (animator.GetCurrentAnimatorStateInfo(0).IsName("Stroke")) { currentTime += Time.deltaTime; yield return(null); } endAttack?.Invoke(); }
void AttackGo() { int damage = 0; switch (weapon) { case 0: damage = 1; break; case 1: damage = (UnityEngine.Random.Range(0, 100) < 25) ? 5 : 1; break; case 2: damage = 1; break; case 3: damage = 3; break; default: break; } Fight2D.Action(punch1.position, punchRadius, 9, damage, isFacingRight); }
void AttackGo() { EnemyFight2D.Action(punch1.position, punchRadius, 10, damage, isFacingLeft, "Rogue"); if (isBalist) { Fight2D.Action(punch1.position, punchRadius * 2f, 9, 1, isFacingLeft); isBalist = false; StartCoroutine("AttackInBalist"); } }
void AttackGo() { if (isFacingRight) { Fight2D.Action(punch1.position, punchRadius, 9, 1, isFacingRight); } else { Fight2D.Action(punch2.position, punchRadius, 9, 1, isFacingRight); } }
private void Update() { int size = coll.OverlapCollider(filter, colls); for (int i = 0; i < size; i++) { Damageable target = colls[i].GetComponent <Damageable>(); if (target != null) { Fight2D.Action(this, target); } } }
void RoosterMagicBlock() { if (MP >= costBlock) { MP -= costBlock; Fight2D.Action(punchBlock.position, punchBlockRadius, 9, 1, isFacingRight); } else { Block = false; anim.SetBool("Block", false); gameObject.GetComponent <PlayerHP>().isblock = false; } }
void OnTriggerEnter2D(Collider2D coll) { if (!coll.isTrigger) // чтобы пуля не реагировала на триггер { switch (coll.tag) { case "Player": Fight2D.Action(this.transform.position, 0.15f, 11, damage, false); Destroy(gameObject); break; case "Enemy_2": // что-то еще... break; } } }
// private private void AttackOnAnimEvent() { var layerMask = LayerMask.GetMask("Player"); var layerMaskBlock = LayerMask.GetMask("Block"); var playerCollider = Physics2D.OverlapCircle(GetGlobalAttackPoint(), radius, layerMask); var playerColliders = Physics2D.OverlapCircleAll(GetGlobalAttackPoint(), radius, layerMask | layerMaskBlock); GameObject nearObject = Fight2D.NearTarget(localAttackPoint, playerColliders); bool inBlock = nearObject != null && nearObject.tag == "BLOCK"; if (playerCollider == null) { return; } var playerHealth = playerCollider.GetComponent <Health>(); if (playerHealth == null) { return; } playerHealth.Hit(damage, inBlock); }
void Update() { // Сохранение значений PlayerPrefs.SetInt("Char", charapter); PlayerPrefs.SetInt("Coins", coins); PlayerPrefs.SetInt("Silver", silver); PlayerPrefs.SetInt("Cooper", cooper); PlayerPrefs.SetInt("Exp", exp); PlayerPrefs.SetInt("Hp", hp); PlayerPrefs.SetInt("Mp", mp); PlayerPrefs.SetString("Helmet", helmet_id); PlayerPrefs.SetString("Plate", plate_id); PlayerPrefs.SetString("Gloves", gloves_id); PlayerPrefs.SetString("Boots", boots_id); // Считаем текущие характеристики персонажа. (Стандартные + бонусные) max_hp = Con * 28; max_mp = Int * 12; Str = Def_Str + Bon_Str; Dex = Def_Dex + Bon_Dex; Con = Def_Con + Bon_Con; Int = Def_Int + Bon_Int; // Действия if (Input.GetButtonDown("attack")) { StartCoroutine(attack_func()); Fight2D.Action(punch1.position, punch1Radius, 10, full_damage, false); } if (Input.GetButtonDown("spell_1")) { if (spell1 == false) { Fight2D.Action(punch1.position, punch1Radius, 10, full_damage + 15, false); } StartCoroutine(spell1_func()); } if (Input.GetButtonDown("spell_2")) { if (spell2 == false) { Fight2D.Action(punch1.position, punch1Radius, 10, full_damage + 25, false); } StartCoroutine(spell2_func()); } if (Input.GetButtonDown("spell_3")) { if (spell3 == false) { hp = hp + 10; if (hp > max_hp) { hp = max_hp; } } StartCoroutine(spell3_func()); } // Задаем параметры персонажам // 1 персонаж if (charapter == 1) { Def_Str = 5; Def_Dex = 5; Def_Con = 5; Def_Int = 5; full_damage = def_damage + (Str / 2); } // 2 персонаж if (charapter == 2) { Def_Str = 2; Def_Dex = 6; Def_Con = 4; Def_Int = 8; full_damage = def_damage + (Str / 2); } // 3 персонаж if (charapter == 3) { Def_Str = 4; Def_Dex = 7; Def_Con = 5; Def_Int = 4; full_damage = def_damage + (Str / 2); } // 4 персонаж if (charapter == 4) { Def_Str = 8; Def_Dex = 3; Def_Con = 7; Def_Int = 2; full_damage = def_damage + (Str / 2); } // 5 персонаж if (charapter == 5) { Def_Str = 6; Def_Dex = 4; Def_Con = 8; Def_Int = 2; full_damage = def_damage + (Str / 2); } // ТЕСТ ФУНКЦИИ if (Input.GetKeyDown(KeyCode.T)) { coins = 1; silver = 1; cooper = 1; exp = 1; hp = 10; mp = 10; } if (Input.GetKeyDown(KeyCode.Y)) { coins = 60000; silver = 100; cooper = 20; exp = 10000; hp = max_hp; mp = max_mp; helmet_id = "helmet_1"; plate_id = "plate_1"; gloves_id = "gloves_1"; boots_id = "boots_1"; } if (Input.GetKeyDown(KeyCode.Return)) { exp = exp + 100; } }
void hitTarget() { var enemyLayer = LayerMask.NameToLayer("Enemy"); Fight2D.Action(attack.position, 0.66f, enemyLayer, 35, false); }
void hitEnd() { Fight2D.Action(punch1.position, punch1Radius, 9, 50, false); //событие в анимации, чтобы удар был после неё }
void UpdateMoving(float inputX, float inputY, bool running, bool debugCheat, bool onTheGround, bool attack, bool jump) { // Ожидание прыжка (для анимации) if (!running) { jump |= wJump > 0; if (!jump) { wJump = 0; } else { wJump += Time.deltaTime; } jump = wJump > 0.12f; if (jump) { wJump = 0; } } if (canMove) { if (inputX != 0) { transform.localScale = new Vector3(inputX > 0 ? defaultScaleX : -defaultScaleX, transform.localScale.y, transform.localScale.y); } } if (!canMove) { return; } jumpRemember -= Time.deltaTime; if (!onVine) { transform.Translate(new Vector2(inputX * Time.deltaTime * speed * (running ? 1.5f : 1), 0)); if (jump && onTheGround) { jumpRemember = jumpRememberTime; } if ((jumpRemember > 0) && onTheGround) { jumpRemember = 0; rb.AddForce(new Vector2(0, jumpForce * (debugCheat ? 25 : 10)), ForceMode2D.Impulse); } if (attack) { //точкa контакта, радиус, номер слоя юнита, урон по цели, только один враг получает урон Fight2D.Action(punch.position, punchRadius, 9, 1, false); } } else { if (inputY != 0) { rb.velocity = new Vector2(0, inputY * 5); } else { rb.velocity = new Vector2(0, 0); } if (jump) { onVine = false; rb.gravityScale = 1; if (transform.localScale.x < 0) { rb.velocity = new Vector2(-5f, 3f); } else if (transform.localScale.x > 0) { rb.velocity = new Vector2(5f, 3f); } } } }