private void slashSword() //executed on local instance { Transform player = PCO.playerBoundingCollider.transform; Vector3 slashDir = player.right; if (!isMouseToTheRight()) { slashDir = player.right * -1f; } Vector3 slashPoint = player.position; slashPoint += slashDir * PCO.playerBoundingCollider.bounds.extents.x; slashPoint += slashDir * swordLength / 2; hitCenterGizmoVector = slashPoint; Collider2D[] hits = Physics2D.OverlapCircleAll(slashPoint, swordLength); foreach (Collider2D c in hits) { Rigidbody2D RB = c.GetComponent <Rigidbody2D>(); if (RB && c.gameObject != PCO.PC.gameObject) { RB.AddForce(player.right * knockBackForce); // Debug.Log(c.name); } EnemyRecieveDamage ERD = c.GetComponent <EnemyRecieveDamage>(); if (ERD) //hit enemy with ERD componenet //ERD.CmdTakeDamageWithGO(swordDamage,PD.gameObject);//cant because no autority { PCO.relayERDAttack(ERD, swordDamage, PD); } PlayableCharacter PC = c.GetComponent <PlayableCharacter>(); if (PC && PC.gameObject != PCO.PC.gameObject) //hit another player { PlayerGiveDamage PGD = PCO.GetComponent <PlayerGiveDamage>(); if (PGD) { PGD.giveDamageToPlayableCharacter(swordDamage, PC.PCO.gameObject); } else { Debug.Log("can't find give damage"); } } } if (slashingEffect) { GameObject GO = Instantiate(slashingEffect, slashPoint, Quaternion.identity); GO.transform.parent = this.transform; } else { Debug.Log("slashingEffect not assigned"); } }
private void Update() { if (active && Input.GetMouseButtonDown(0) && Time.time - lastTpTime >= coolDownTime) { lastTpTime = Time.time; //AudioManager.instance.play("throw"); parentCO.GetComponent <ShootBullets>().Shoot(); } }