void OnTriggerStay(Collider other) { // Debug.Log(string.Format("Entity {0} touched other: {1}", this.collider.name, other.name)); BaseCollision collision = other.GetComponent <BaseCollision>(); // tell this entity that someone else touched it if (collision is EntityCollision) { EntityCollision entityCollision = (EntityCollision)collision; entity.TouchedByEntity(entityCollision.entity); } // tell this entity that some one else's weapon touched it else if (collision is WeaponCollision) { WeaponCollision weaponCollision = (WeaponCollision)collision; entity.TouchedByWeapon(weaponCollision.weapon); } else if (collision is WallCollision) { entity.TouchedByWall(other); } else if (collision is PotCollision) { PotCollision potCollision = (PotCollision)collision; entity.TouchedByPot(potCollision.pot); } }
public override void Start(Player player, LocalPlayerController controller, System.Object param) { base.Start(player, controller, param); actionName = param as string; if (actionName == null) { actionName = "Attack1"; } player.animator.updateMode = AnimatorUpdateMode.AnimatePhysics; player.animator.applyRootMotion = true; if (actionName == "Attack2") { player.SetUpperAniState(Player.StateNameHash.attack2, true); player.SetLowerAniState(Player.StateNameHash.attack2, true); } else { player.SetUpperAniState(Player.StateNameHash.attack1, true); player.SetLowerAniState(Player.StateNameHash.attack1, true); } wc = player.weaponCollision; if (wc != null) { wc.onHit += this.OnWeaponHit; } hitList.Clear(); }
public override void Shoot() { if (WeaponCollision.IsColliding() || IsReloading) { IsShooting = false; } else { IsShooting = true; } }
public override void Shoot() { if (Time.time > CooldownCollapsed && !IsReloading && !WeaponCollision.IsColliding()) { PhotonView.RPC("ShootEffectRpc", RpcTarget.All, WeaponSocket.transform.forward); PushBack(); ReduceAmmo(); CameraShake.StartShake(Weapon.ShakeProfile); CooldownCollapsed = Time.time + Weapon.FireRate; } }
/// <summary>Activate Charging.</summary> public override void Shoot() { if (WeaponCollision.IsColliding() || !HasAmmo) { return; } if (Time.time > CooldownCollapsed && !m_charge) { m_charge = true; PhotonView.RPC("ChargeEffect", RpcTarget.AllViaServer); } }
void Start() { anim = GetComponent <Animator>(); capCol = GetComponent <CapsuleCollider>(); rigidbody = GetComponent <Rigidbody>(); agent = GetComponent <NavMeshAgent>(); charStats = GetComponent <PlayerStats>(); SetupAnimator(); gm = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>(); wepCol = GetComponentInChildren <WeaponCollision>(); agent.stoppingDistance = charStats.attackRange; holdPos = generalCharacter.position; }
void Start() { anim = GetComponent <Animator>(); capCol = GetComponent <CapsuleCollider>(); cam = Camera.main.transform; if (GameObject.FindGameObjectWithTag("GameManager") != null) { gm = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>(); gm.CurrentPlayers.Add(this.transform); } rigidbody = GetComponent <Rigidbody>(); wepCol = GetComponentInChildren <WeaponCollision>(); wepMan = GetComponent <WeaponManager>(); SetupAnimator(); }
void OnTriggerStay(Collider other) { BaseCollision collision = other.GetComponent <BaseCollision>(); if (collision is EntityCollision) { EntityCollision entityCollision = (EntityCollision)collision; pot.TouchedByEntity(entityCollision.entity); } else if (collision is WeaponCollision) { WeaponCollision weaponCollision = (WeaponCollision)collision; pot.TouchedByWeapon(weaponCollision.weapon); } else if (collision is WallCollision) { pot.TouchedByWall(); } }
/// <summary> /// Checks if Weapon is able to Shoot, applies Damage, Reduce ammo, Camera Shake and Push back. /// </summary> public override void Shoot() { if (WeaponCollision.IsColliding() || IsReloading) { IsShooting = false; return; } IsShooting = true; if (Time.time <= CooldownCollapsed) { return; } if (m_target != null && PlayerHelper.ValidateTarget(m_target)) { var hitted = m_target.GetComponent <IDamageable>().ApplyDamage(Weapon.Damage); if (hitted) { HitEvent.Invoke(); ScriptableTextDisplay.Instance.InitializeStackingScriptableText(5, m_target.transform.position, Weapon.Damage.ToString(), m_target.name); } } //PushBack PushBack(); //Ammo ReduceAmmo(); //Camera Shake CameraShake.StartShake(Weapon.ShakeProfile); CooldownCollapsed = Time.time + Weapon.FireRate; }
void BeginAttack() { WeaponCollision wc = GetComponentInChildren <WeaponCollision>(); wc.currentCollisions.Clear(); WeaponAttack chainAttack = weaponObject.chainAttack[bufferedAttack]; windupTime = chainAttack.windupTime; backswingTime = chainAttack.backswingTime; foreach (SwingEffect swing in chainAttack.swingEffects) { swing.IsServer = isServer; swing.OnSwing(this); } Animator anim = GetComponentInChildren <Animator>(); if (wc == null || wc.type.Equals("sword")) { anim.Play("SwordSwing_Right"); } else { anim.Play("WeaponStab_Right"); } //Play random swing sound // // // attackStage = 0; //Client and server reset value at same time bufferedAttack = -1; }
void OnTriggerStay(Collider other) { // tell the this weapon's owner that another weapon touched it. BaseCollision collision = other.GetComponent <BaseCollision>(); if (collision is WeaponCollision) { WeaponCollision weaponCollision = (WeaponCollision)collision; weapon.owner.WeaponTouchedByWeapon(weaponCollision.weapon); } // tell the this weapon's owner that someone touched it. else if (collision is EntityCollision) { EntityCollision entityCollision = (EntityCollision)collision; weapon.owner.WeaponTouchedByEntity(entityCollision.entity); } else if (collision is PotCollision) { PotCollision potCollision = (PotCollision)collision; weapon.owner.WeaponTouchedByPot(potCollision.pot); } }
//更换右手武器 public void ChangeWeapon(WeaponType weapon) { if (weapon != this.weaponType) { if (rightWeapon != null) { //原来有武器的话,要销毁 Destroy(rightWeapon.gameObject); rightWeapon = null; weaponCollision = null; gun = null; } if (shield != null) { Destroy(shield.gameObject); shield = null; } this.weaponType = weapon; if (weapon == WeaponType.Melee) { //在右手上加上武器 UnityEngine.Object res = Resources.Load("Weapons/Sword"); rightWeapon = GameObject.Instantiate(res, this.rightHand, false) as GameObject; weaponCollision = rightWeapon.GetComponent <WeaponCollision>(); res = Resources.Load("Weapons/Shield"); shield = GameObject.Instantiate(res, this.leftArm, false) as GameObject; } else if (weapon == WeaponType.Pistol) { //在右手上加上武器 UnityEngine.Object res = Resources.Load("Weapons/Pistol"); rightWeapon = GameObject.Instantiate(res, this.rightHand, false) as GameObject; gun = rightWeapon.GetComponent <Gun>(); } if (rightWeapon != null) { MeshRenderer mr = rightWeapon.GetComponent <MeshRenderer>(); if (playerType == PlayerType.Remote || playerType == PlayerType.LocalAI) { mr.material = enemyMat; } } if (shield != null) { MeshRenderer mr = shield.GetComponent <MeshRenderer>(); if (playerType == PlayerType.Remote || playerType == PlayerType.LocalAI) { mr.material = enemyMat; } } if (weaponCollision != null) { weaponCollision.colliderEanbled = false; } } }
// 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()); } }