private void LoadDamageObject(DamageObject dobject) { if (dobject.Destructible) { checkBox1.Checked = true; } if (dobject.Cripple) { checkBox2.Checked = true; } else { groupBox1.Enabled = false; } textBox1.Text = dobject.Damage.ToString(); if (dobject.GameSprite.PathImage[0] != null) { pictureBox1.Image = new Bitmap(dobject.GameSprite.PathImage[0]); } if (dobject.GameSprite.PathImage[1] != null) { pictureBox2.Image = new Bitmap(dobject.GameSprite.PathImage[1]); } temppath[0] = dobject.GameSprite.PathImage[0]; temppath[1] = dobject.GameSprite.PathImage[1]; }
void CreateImpact(Vector3 pos, Vector3 normal) { GunObject gun = gunHandler.gun; if (gun.impactEffect == null || gunHandler.ImpactPool == null) { return; } PooledObject impact = gunHandler.ImpactPool.get(); impact.transform.position = pos; impact.transform.rotation = Quaternion.LookRotation(normal); if (!(impact as DamageObject)) { return; } DamageObject dmgImpact = (impact as DamageObject); dmgImpact.Damage = gun.bulletDamage; int simulation = dmgImpact.Simulate(); if (simulation < 0) { return; } ui.ShowHitmarker(simulation > 0); //Damages and shows hitmarker }
//deals damage to an enemy target private void DealDamageToEnemy(GameObject enemy) { DamageObject d = new DamageObject(0, gameObject); if (playerState.currentState == PLAYERSTATE.PUNCH) { d = PunchAttackData [attackNum]; } else if (playerState.currentState == PLAYERSTATE.KICK) { d = KickAttackData [attackNum]; } else if (playerState.currentState == PLAYERSTATE.THROWKNIFE) { d.damage = currentWeapon.data; d.attackType = AttackType.KnockDown; } else if (playerState.currentState == PLAYERSTATE.JUMPKICK) { d = JumpKickData; jumpKickActive = false; //hit only 1 enemy } d.inflictor = gameObject; //subsctract health from enemy HealthSystem hs = enemy.GetComponent <HealthSystem>(); if (hs != null) { hs.SubstractHealth(d.damage); } enemy.GetComponent <EnemyAI>().Hit(d); }
private void Start() { _DM = gameObject.AddComponent <DamageObject>(); _DM._OnDamage = OnHit; _DM._OnDeath = OnDeath; GetComponent <Interactable>().OnNearEnter = OnTrigger; }
private void DoWhatEverOnDamageHere(DamageObject damageObject, bool stay = false) { _health.amount -= damageObject.damageAmount * (stay ? 1f : Time.deltaTime); _healthText.text = $"{Mathf.RoundToInt(_health.amount)}HP"; _rb2D.AddForce(Vector2.up * 100); StartCoroutine(AnimateOnDamage()); }
public void DoAttack() { playerState.SetState(PLAYERSTATE.ATTACK); anim.Attack(0); DamageObject d = new DamageObject(20, this.gameObject, 0.5f, Vector3.zero, 0.005f); CheckForHit(d); }
public void DoStagger() { playerState.SetState(PLAYERSTATE.STAGGER); anim.Stagger(); DamageObject d = new DamageObject(20, this.gameObject, 0.5f, Vector3.zero, 0.005f); d.attackType = AttackType.Stagger; CheckForHit(d); }
//deal damage to the current target void DealDamageToTarget() { if (target != null) { DamageObject d = new DamageObject(attackDamage, gameObject); d.attackType = AttackType.Default; target.SendMessage("Hit", d, SendMessageOptions.DontRequireReceiver); } }
public void DoSprintAttack() { playerState.SetState(PLAYERSTATE.SPRINTATTACK); anim.SprintAttack(); DamageObject d = new DamageObject(20, this.gameObject, 1.5f, Vector3.zero, 0.01f); d.attackType = AttackType.KnockDown; CheckForHit(d); }
void Start() { d_o = gameObject.AddComponent <DamageObject>(); d_o.Penetration = 3; d_o.IsDestroy = false; d_o.IsDamage = true; d_o.Damages = new DamageData() { Batting = blunt, Slash = slash }; }
// Use this for initialization void Start() { npcLayerMask = LayerMask.NameToLayer("NPC"); playerLayerMask = LayerMask.NameToLayer("Player"); attackLayerMask = LayerMask.NameToLayer("Attack"); d = new DamageObject(20, AttackType.KnockDown, PowerType.Medium, this.gameObject.transform.parent.gameObject, 1f, Vector3.down, 0.005f, 10f); d.lag = 0f; verticalVelocity = 12; moveVectorX = 2; state = PLAYERSTATE.SHENGLONGBA; }
void Awake() { enemyMovement = GetComponent <EnemyMovement>(); thisRigidbody2D = GetComponent <Rigidbody2D>(); damageObject = GetComponent <DamageObject>(); spawnHealth = GetComponent <SpawnHealth>(); spawnForceField = GetComponent <SpawnForceField>(); damageTimeout = 0.4f; blobState = State.Roaming; startPosition = transform.position; thisEnemy = gameObject; }
void OnTriggerEnter2D(Collider2D col) { if (col.CompareTag("Enemy")) { DamageObject d = new DamageObject(Damage, gameObject); d.attackType = AttackType.KnockDown; col.GetComponent <EnemyAI>().Hit(d); col.GetComponent <HealthSystem>().SubstractHealth(d.damage); GlobalAudioPlayer.PlaySFX(sfx); ShowHitEffect(); Destroy(gameObject); } }
public void RecieveDamage(DamageObject prAttack) { currentHealth -= prAttack.damage - armour; updateHealthBar(); triggerHandler.FireTriggerList(Triggers.OnAttack, prAttack.originObject, gameObject); if (currentHealth <= 0) { OnDeath(); triggerHandler.FireTriggerList(Triggers.OnDeath, prAttack.originObject, gameObject); prAttack.originObject.GetComponent <UnitTriggerHandler>().FireTriggerList(Triggers.OnDeath, prAttack.originObject, gameObject); } }
public void Hit(DamageObject d) { //stop moving Move(Vector3.zero, 0); //look towards inflictor if (target != null) { target = d.inflictor; } LookAtTarget(); //show hit effect if (!isDead) { ShowHitEffectAtPosition(transform.position + Vector3.up * Random.Range(1.0f, 2.0f)); GlobalAudioPlayer.PlaySFX("PunchHit"); } //enemy can be hit if (!HitStates.Contains(enemyState) && !isDead) { //showHitEffectAtPosition ShowHitEffectAtPosition(transform.position + Vector3.up * Random.Range(1.0f, 2.0f)); //sfx GlobalAudioPlayer.PlaySFX("PunchHit"); //knockdown if (d.attackType == AttackType.KnockDown) { enemyState = ENEMYSTATE.KNOCKDOWN; StartCoroutine(KnockDown(DirectionToPos(d.inflictor.transform.position.x))); } else { //normal hit animator.Hit(); enemyState = ENEMYSTATE.HIT; } } //unit is dead if (GetComponent <HealthSystem>() != null && GetComponent <HealthSystem>().CurrentHp == 0 && !isDead) { Move(Vector3.zero, 0); UnitIsDead(); } }
void DoTheMethod() { var go = Fsm.GetOwnerDefaultTarget(gameObject); if (go == null) { return; } dam = new DamageObject(damage.Value, attackType, inflictor.Value); dam.range = range.Value; dam.comboResetTime = comboResetTime.Value; var dObject = dam; theScript.Hit(dObject); }
private void Save(DamageObject dobject) { dobject.Destructible = checkBox1.Checked; dobject.Cripple = checkBox2.Checked; dobject.Damage = Convert.ToInt32(textBox1.Text); dobject.UserSizeImage = dobject.GameSprite.PathImage[0] != temppath[0] ? new SizeF(0, 0) : dobject.UserSizeImage; dobject.GameSprite.PathImage[0] = temppath[0]; dobject.GameSprite.PathImage[1] = temppath[1]; ISprite isprite = dobject; isprite.LoadSprite(); }
protected void OnTriggerEnter2D(Collider2D collider) { bulletHero bulletHero = collider.GetComponent <bulletHero>(); if (bulletHero) { ReciveDamage(1, true); } DamageObject damageObject = collider.GetComponent <DamageObject>(); if (damageObject) { ReciveDamage(100, false); } }
//checks if we have hit something (animation event) private void CheckForHit(DamageObject d) { int dir = -1; if (facingRight) { dir = 1; } float moveTime = 0.5f; //StartCoroutine (WaitBeforeRaycast (d, dir)); transform.GetChild(3).gameObject.SetActive(true); //StartCoroutine(GetComponentInChildren<NormalAttack>().WaitBeforeCollide(d, dir)); StartCoroutine(GetComponentInChildren <NormalAttack>().WaitBeforeCollide(d, dir)); }
private void OnTriggerEnter(Collider other) { int dir = -1; if (gameObject.transform.parent.GetComponent <Action>().facingRight) { dir = 1; } if (gameObject.transform.parent.GetComponent <PlayerState>().currentState == PLAYERSTATE.NOTIDLE && other.gameObject.transform != gameObject.transform.parent.transform) { DamageObject d1 = new DamageObject(20, this.gameObject.transform.parent.gameObject, 1f, Vector3.down, 0.1f, 6f); d1.attackType = AttackType.KnockDown; d1.lag = 0f; other.gameObject.GetComponent <Action>().getHit(d1, dir); } }
//we are hit 被攻击 public void Hit(DamageObject d) { //Camera Shake CamShake camShake = Camera.main.GetComponent <CamShake>(); if (camShake != null) { camShake.Shake(.2f); } //check for hit anim.SetAnimatorTrigger("Hit1"); enemyState = UNITSTATE.HIT; //add small force from the impact LookAtTarget(d.inflictor.transform); anim.AddForce(-knockbackForce); }
//Attack public void ATTACK() { //don't attack when player is jumping var playerMovement = target.GetComponent <PlayerMovement>(); if (!AttackPlayerAirborne && playerMovement != null && playerMovement.jumpInProgress) { return; } else { //init enemyState = UNITSTATE.ATTACK; Move(Vector3.zero, 0f); LookAtTarget(target.transform); TurnToDir(currentDirection); //pick random attack if (PickRandomAttack) { AttackCounter = Random.Range(0, AttackList.Length); } //play animation animator.SetAnimatorTrigger(AttackList[AttackCounter].animTrigger); //go to the next attack in the list if (!PickRandomAttack) { AttackCounter += 1; if (AttackCounter >= AttackList.Length) { AttackCounter = 0; } } lastAttackTime = Time.time; lastAttack = AttackList [AttackCounter]; lastAttack.inflictor = gameObject; //resume Invoke("Ready", AttackList [AttackCounter].duration); } }
public void ATTACK() { //玩家跳跃时不要攻击 var playerMovement = target.GetComponent <PlayerMovement>(); if (!AttackPlayerAirborne && playerMovement != null && playerMovement.jumpInProgress) { return; } else { enemyState = PLAYERSTATE.ATTACK; Move(Vector3.zero, 0f); LookAtTarget(target.transform); TurnToDir(currentDirection); //选择随机攻击 if (PickRandomAttack) { AttackCounter = Random.Range(0, AttackList.Length); } //播放动画 playerAnimator.SetAnimatorTrigger(AttackList[AttackCounter].animTrigger); //转到列表中的下一个攻击 if (!PickRandomAttack) { AttackCounter += 1; if (AttackCounter >= AttackList.Length) { AttackCounter = 0; } } lastAttackTime = Time.time; lastAttack = AttackList[AttackCounter]; lastAttack.inflictor = gameObject; //恢复 Invoke("Ready", AttackList[AttackCounter].duration); } }
public void Ready(string animName) { if (playerState.currentState == PLAYERSTATE.KNOCKDOWN || playerState.currentState == PLAYERSTATE.KNOCKBACK || playerState.currentState == PLAYERSTATE.PARALYZED) { if (animName == "PlayerKnockDown" || animName == "PlayerParalyzed") { // controller.enabled = true; anim.Idle(); playerState.SetState(PLAYERSTATE.IDLE); } else //Hit's ready call, do nothing if knocked down. { return; } } else if (playerState.currentState == PLAYERSTATE.ATTACK && (animName == "PlayerAttack0" || animName == "PlayerAttack1" || animName == "PlayerAttack2")) { if (continueAttackCombo) { DamageObject d = new DamageObject(20, this.gameObject, 0.3f, Vector3.zero, 0.005f); CheckForHit(d); doAttack(); continueAttackCombo = false; } else { attackNum = 0; anim.Idle(); playerState.SetState(PLAYERSTATE.IDLE); } } else if ((playerState.currentState == PLAYERSTATE.STAGGERED && animName == "PlayerStaggered") || (playerState.currentState == PLAYERSTATE.HIT && animName == "PlayerHit") || (playerState.currentState == PLAYERSTATE.STAGGER && animName == "PlayerStagger") || (playerState.currentState == PLAYERSTATE.SPRINTATTACK && animName == "PlayerSprintAttack")) { anim.Idle(); playerState.SetState(PLAYERSTATE.IDLE); } }
/// <summary> /// 攻击 /// </summary> public void ATTACK() { //print("gongji "); var playerMovement = target.GetComponent <PlayerMovement>(); if (!attackPlayerAirborne && playerMovement != null && playerMovement.jumpInProgress) { return; } else { enemyState = UNITSTATE.ATTACK; Move(Vector3.zero, 0f); LookAtTarget(target.transform); TurnToDir(currentDirection); if (pickRandomAttack) { attackCounter = Random.Range(0, attackList.Length); } anim.SetAnimatorTrigger(attackList[attackCounter].animTrigger); if (!pickRandomAttack) { attackCounter += 1; if (attackCounter >= attackList.Length) { attackCounter = 0; } } lastAttackTime = Time.time; lastAttack = attackList[attackCounter]; Invoke("READY", attackList[attackCounter].duration); } }
// Called regardless of if there are non-kinematic RigidBody's involved private void ProcessCollision(GameObject otherGameObject) { if (otherGameObject.layer == LayerMask.NameToLayer("BaseLevel")) { } else if (otherGameObject.layer == LayerMask.NameToLayer("Props")) { } else if (otherGameObject.layer == LayerMask.NameToLayer("Enemies")) { DamageObject damageObj = otherGameObject.GetComponentInParent <DamageObject>(); if (damageObj != null) { if (GameCoordinator.Instance.Health > 0) { GameCoordinator.Instance.Health -= damageObj.Value; if (GameCoordinator.Instance.Health <= 0) { GameCoordinator.Instance.Health = 0; } Debug.Log($"Took damage {damageObj.Value} from enemy {otherGameObject.name}"); CheckWinLossConditions(); } } } else if (otherGameObject.layer == LayerMask.NameToLayer("Player")) { } else if (otherGameObject.layer == LayerMask.NameToLayer("Collectables")) { if (!m_IsGameOver) { CollectableObject co = otherGameObject.GetComponentInParent <CollectableObject>(); if (co != null) { GameCoordinator.Instance.Health += co.RechargeValue; GameCoordinator.Instance.Ammo += co.AmmoValue; if (co.IsLevelToken) { m_LevelTokens.Add(otherGameObject.name); } } Debug.Log("Collected " + otherGameObject.name); Destroy(otherGameObject); CheckWinLossConditions(); } } else if (otherGameObject.layer == LayerMask.NameToLayer("PlayerProjectiles")) { } else if (otherGameObject.layer == LayerMask.NameToLayer("EnemyProjectiles")) { DamageObject damageObj = otherGameObject.GetComponentInParent <DamageObject>(); if (damageObj != null) { if (GameCoordinator.Instance.Health > 0) { GameCoordinator.Instance.Health -= damageObj.Value; if (GameCoordinator.Instance.Health <= 0) { GameCoordinator.Instance.Health = 0; } Debug.Log($"Took damage {damageObj.Value} from projectile {otherGameObject.name}"); CheckWinLossConditions(); } } } }
private void Awake() { _DamageObject = gameObject.AddComponent <DamageObject>(); _DamageObject._OnDamage = OnHit; _DamageObject._OnDeath = OnDeath; }
public void SetDamage(DamageObject d) { damage = d; }
public void getHit(DamageObject d, int fixedDir = 0) { bool wasHit = true; if (playerState.currentState == PLAYERSTATE.KNOCKDOWN) { wasHit = false; } // HOTFIX for addForce making character not grounded. if (controller.isGrounded == false && playerState.currentState != PLAYERSTATE.HIT && playerState.currentState != PLAYERSTATE.DEFENDING) { d.attackType = AttackType.KnockDown; HitKnockDownCount = 0; } //defend if (playerState.currentState == PLAYERSTATE.DEFENDING) { wasHit = false; UpdateDefenseCounter(); if (d.attackType == AttackType.Stagger || d.attackType == AttackType.KnockDown) { wasHit = true; anim.Staggered(); playerState.SetState(PLAYERSTATE.STAGGERED); anim.ShowStaggerEffect(); anim.AddForce(0.005f, d.inflictor.GetComponent <Action>().facingRight); DefenseCount = 0; return; } else if (DefenseCount >= DefenseThreshold) { anim.Staggered(); playerState.SetState(PLAYERSTATE.STAGGERED); anim.ShowStaggerEffect(); anim.AddForce(0.005f, d.inflictor.GetComponent <Action>().facingRight); DefenseCount = 0; return; } else { // if(BlockAttacksFromBehind || isFacingTarget (d.inflictor)) wasHit = false; // if(!wasHit){ //// GlobalAudioPlayer.PlaySFX ("Defend"); //// anim.ShowDefendEffect(); // anim.ShowDefendEffect(); anim.AddForce(0.005f, d.inflictor.GetComponent <Action>().facingRight); // } } } //parry //need to add math for different types of attack //if (playerState.currentState == PLAYERSTATE.ATTACK) { // anim.ShowParryEffect(); // wasHit = false; //} if (wasHit) { UpdateHitCounter(); } if (HitKnockDownCount >= HitKnockDownThreshold) { d.attackType = AttackType.KnockDown; HitKnockDownCount = 0; } //start knockDown sequence if (wasHit && playerState.currentState != PLAYERSTATE.KNOCKDOWN) { // GetComponent<HealthSystem> ().SubstractHealth (d.damage); anim.ShowHitEffect(); moveVector.x = 0; moveVector.z = 0; verticalVelocity = 0; if (d.attackType == AttackType.Paralyze) { playerState.SetState(PLAYERSTATE.PARALYZED); anim.Paralyzed(); } else if (d.attackType == AttackType.KnockDown) { playerState.SetState(PLAYERSTATE.KNOCKBACK); KnockBack(d.inflictor); verticalVelocity = 5f; if (d.verticalForce != 0f) { verticalVelocity = d.verticalForce; } anim.AddForce(d.force * 20, d.inflictor.GetComponent <Action>().facingRight); } else { playerState.SetState(PLAYERSTATE.HIT); anim.Hit(); anim.AddForce(d.force, d.inflictor.GetComponent <Action>().facingRight); } } }
public DamageBlockLowBuilder(Resources resources, Vector2 position) { damageObject = new DamageObject(position); this.resources = resources; }