public void AttackEnemy(AttackCollision attackCollision) { var newEnemys = attackCollision.GetHittedChars(); var currentEnemys = newEnemys.Except(_hittedEnemy).ToList(); _hittedEnemy.AddRange(newEnemys); AttackEnemyCheck(currentEnemys); }
public void AttackEnemy(AttackCollision attackCollision) { var chars = attackCollision.GetHittedChars();//맞은놈들 캐릭터임 foreach (var cha in chars) { Debug.Log(cha._id); if (_socketManager.characterList[cha._id]._defense) { _animator.SetTrigger("exit_attack"); _coolTime = _maxCooltime * 3; } else { _socketManager.socket.EmitJson("hit", JsonConvert.SerializeObject(new { target = cha._id, dmg = 30 })); } } }
void Start() { //origin = origin + new Vector2(attack.offset.x * direction, attack.offset.y); attackPath = attack.attackPath; if (attack.targetType == Attack.TargetType.TargetStraight) { RaycastHit2D hitInfo; hitInfo = Physics2D.Raycast(transform.position, Vector2.right, attack.offset.x); if (hitInfo.collider.gameObject.tag == "Enemy") { //transform.position = hitInfo.collider.gameObject.transform.position; } else { //transform.position = origin; } } else { print(origin); //transform.position = origin; } gameObject.tag = "Attack"; rb = gameObject.AddComponent <Rigidbody2D>(); rb.constraints = RigidbodyConstraints2D.FreezeRotation; rb.gravityScale = 0; sr = attack.spriteAnimation.GetComponent <SpriteRenderer>(); velocityDiv = attack.velocityDiv; lifetime = attack.lifetime; xSpeed = attack.speed; if (attack.attackType == Attack.AttackType.Melee) { //mht = sprite } if (attack.bounces) { lifetime *= attack.bounceCount + 1; } if (boxCol = GetComponentInChildren <BoxCollider2D>()) { print("Box Collider Present"); } if (attack.spriteAnimation != null) { GameObject sprite = Instantiate(attack.spriteAnimation, transform.position, Quaternion.identity, this.gameObject.transform); if (direction < 0) { // facing left sprite.transform.localScale = MathC.MultiplyVector(sprite.transform.localScale, MathC.NegaVectorX); } if (attack.attackBase != null) { // Checks for a 2D Collider in the attack base prefab if (sprite.GetComponent <Collider2D>()) { // Adds the attack collision script and links the attack script to it AttackCollision _ac = sprite.AddComponent <AttackCollision>(); _ac._as = this; } } if (attack.attackPath == Attack.AttackPath.Meteor) { sprite.transform.Rotate(new Vector3(0, 0, -45)); ySpeed = xSpeed; } else if (attack.attackPath == Attack.AttackPath.CrashDown) { sprite.transform.Rotate(new Vector3(0, 0, -90)); ySpeed = xSpeed; } } if (col != null) { col.isTrigger = true; } if (attack.attackType == Attack.AttackType.Beam) { if (boxCol == null) { boxCol = attack.spriteAnimation.GetComponent <BoxCollider2D>(); } if (boxCol != null) { boxCol.isTrigger = true; sr.tileMode = SpriteTileMode.Continuous; } else { Debug.LogError("No Box Collider Present on Beam"); } } }
public void OnTriggerStay2D(Collider2D target) //attacks between opposing factions. { if (attackTime >= 1 / attackSpeed) { if (gameObject.tag == "AlliedUnit" && target.tag == "EnemyUnit") { AttackCollision stick = Instantiate(attackStick, myHandle.transform.position, transform.rotation); stick.direction = (mainTarget.transform.position - transform.position).normalized; stick.direction.z = 0.0f; stick.targetCollider = target; stick.damage = attackDamage; stick.intendedTarget = "EnemyUnit"; attackTime = 0.0f; } if (gameObject.tag == "EnemyUnit" && target.tag == "AlliedUnit") { AttackCollision stick = Instantiate(attackStick, myHandle.transform.position, transform.rotation); stick.direction = (mainTarget.transform.position - transform.position).normalized; stick.direction.z = 0.0f; stick.targetCollider = target; stick.damage = attackDamage; stick.intendedTarget = "AlliedUnit"; attackTime = 0.0f; } if (gameObject.tag == "EnemyUnit" && target.tag == "Nexus") { AttackCollision stick = Instantiate(attackStick, myHandle.transform.position, transform.rotation); stick.direction = (mainTarget.transform.position - transform.position).normalized; stick.direction.z = 0.0f; stick.targetCollider = target; stick.damage = attackDamage; stick.intendedTarget = "Nexus"; attackTime = 0.0f; //AttackCollision stick = Instantiate(attackStick, transform.position, transform.rotation); //stick.direction = (mainTarget.transform.position - transform.position).normalized; //stick.direction.z = 0.0f; //target.gameObject.SendMessage("OnHit", attackDamage); //Debug.Log("I send OnHit to" + target); } } //if (hasCollided == false) //{ // if (this.tag == "AlliedUnit" && target.tag == "EnemyUnit" || this.tag == "EnemyUnit" && target.tag == "AlliedUnit") // { // //target.gameObject.SendMessage("OnHit", attackDamage); // //this.gameObject.SendMessage("OnHit", attackDamage); // hasCollided = true; // } // if (this.tag == "EnemyUnit" && target.tag == "Nexus") // { // //target.gameObject.SendMessage("NexusHit", attackDamage); // //Debug.Log(target.name); // hasCollided = true; // Destroy(gameObject); // } //} }