public void GetBehaviour() { if (attackSystem.GetComponent <PlayerBehaviour>() != null) { playerBehaviour = attackSystem.GetComponent <PlayerBehaviour>(); AttackTimeScaleEffect = playerBehaviour.AttackTimeScaleEffect; } else if (attackSystem.GetComponent <EnemyBehaviour>() != null) { enemyBehaviour = attackSystem.GetComponent <EnemyBehaviour>(); } }
// Update is called once per frame void Update() { if (health <= 0) { if (!isLocalPlayer) { UnitManager.i.DestroyUnit(this.gameObject); } else { transform.position = Vector3.zero; FightManager.i.inCombatPlayers--; CmdSetHeatlth(1000, GetComponent <NetworkIdentity>().netId); } } //Doing a windup if (IsInWindup()) { windupTime -= Time.deltaTime * atkRate; //Is windup finished (attack being done now) if (windupTime <= 0) { WeaponCollision wc = GetComponentInChildren <WeaponCollision>(); List <GameObject> objectsHit = new List <GameObject>(); foreach (GameObject go in wc.currentCollisions) { objectsHit.Add(go); } int objectsHitCount = objectsHit.Count; WeaponAttack chainAttack = weaponObject.chainAttack[attackStage]; foreach (SwingEffect swing in chainAttack.swingEffects) { swing.OnBeforeHit(this, objectsHitCount); } foreach (SwingEffect swing in chainAttack.swingEffects) { if (objectsHit.Count == 0) { swing.OnMiss(this); } else { for (int i = 0; i < objectsHitCount && i < chainAttack.cleave; i++) { GameObject obj = objectsHit[i]; swing.OnHit(this, obj, i, objectsHitCount); //Play random hit sound //Apply base damage if (obj == null) { break; } AttackSystem at = obj.GetComponent <AttackSystem>(); if (at != null && at.faction != faction) { at.CmdInflictDamage((int)(20 * atkMult / at.defMult), at.GetComponent <NetworkIdentity>().netId); } } } } } } //Windup was completed else { //Doing backswing if (IsInBackswing()) { backswingTime -= Time.deltaTime * atkRate; //backswing just finished if (backswingTime <= 0) { WeaponAttack chainAttack = weaponObject.chainAttack[attackStage]; foreach (SwingEffect swing in chainAttack.swingEffects) { swing.OnComplete(this); } attackStage = -1; } } //Backswing was completed //E.g. Doing nothing currently else { if (bufferedAttack >= 0) { BeginAttack(); } } } if (Input.GetKeyDown(KeyCode.P) && isLocalPlayer) { print("isLocalplayer"); CmdAttackMessage(IsInWindup()); } }