//OnCantMove overrides the abstract function OnCantMove in MovingObject. //It takes a generic parameter T which in the case of Player is a Wall which the player can attack and destroy. protected override void OnCantMove <T> (T component) { //Check if we're hitting a wall if (component.GetType() == typeof(Wall)) { //Set hitWall to equal the component passed in as a parameter. Wall hitWall = component as Wall; //Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); //Set the attack trigger of the player's animation controller in order to play the player's attack animation. animator.SetTrigger("playerChop"); } else if (component is Enemy) { Enemy hitEnemy = component as Enemy; int damage = attackDamage(); DamageText.text = "Dealt " + damage + " damage!"; hitEnemy.DamageEnemy(damage, this); animator.SetTrigger("playerChop"); } }
//OnCantMove overrides the abstract function OnCantMove in MovingObject. //It takes a generic parameter T which in the case of Player is a Wall which the player can attack and destroy. protected override void OnCantMove <T> (T component) { if (component is Wall) { //Set hitWall to equal the component passed in as a parameter. Wall hitWall = component as Wall; //Call the DamageWall function of the Wall we are hitting. if (hitWall.destructible) { hitWall.DamageWall(wallDamage); animator.SetTrigger("playerChop"); } else { food++; foodText.text = "Food: " + food; } } else { Enemy e = component as Enemy; e.TakeDamage(); animator.SetTrigger("playerChop"); if (e.hp <= 0) { DestroyImmediate(e); } } }
// OnCantMove overrides the abstract function OnCantMove in MovingObject. // It takes a generic parameter T which in the case of Player is a Wall which the player can attack and destroy. protected override void OnCantMove(Transform component) { // Set hitWall to equal the component passed in as a parameter. Wall hitWall = component.GetComponent <Wall>(); Enemy enemy = component.GetComponent <Enemy>(); if (hitWall) { // Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); // Set the attack trigger of the player's animation controller in order to play the player's attack animation. animator.SetTrigger(animationChop); } else if (enemy) { bool kill = enemy.DamageEnemy(enemyDamage); if (kill) { kills++; } // Set the attack trigger of the player's animation controller in order to play the player's attack animation. animator.SetTrigger(animationChop); } }
//OnCantMove is called if Enemy attempts to move into a space occupied by a Player, it overrides the OnCantMove function of MovingObject //and takes a generic parameter T which we use to pass in the component we expect to encounter, in this case Player protected override void OnCantMove <T>(T component) { if (component is Player) { //Declare hitPlayer and set it to equal the encountered component. Player hitPlayer = component as Player; hitPlayer.DamagePlayer(); } else if (component is Wall) { //Set hitWall to equal the component passed in as a parameter. Wall hitWall = component as Wall; //Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); Destroy(gameObject); } /*else if (component is Ally) * { * Ally hitAlly = component as Ally; * * hitAlly.DamageAlly(playerDamage); * Destroy(gameObject); * }*/ //Destroy(gameObject); //Call the RandomizeSfx function of SoundManager passing in the two audio clips to choose randomly between. SoundManager.instance.RandomizeSfx(attackSound1, attackSound2); }
void PlayAttack(string id, int x, int y, int hp, string target, int del) { if (id == "1") { player.OnCantMove(hp); if (target != null) { if (idFood.ContainsKey(target)) { GameObject go = idFood[target]; player.eatSound(); if (del == 1) { RFood(target, x, y); } } else { if (idWall.ContainsKey(target)) { GameObject go = idWall[target]; Wall gWall = go.GetComponent <Wall>(); gWall.DamageWall(); if (del == 1) { RWall(target, x, y); } } } } } }
protected override void OnCantMove <T> (T component) { Wall hitWall = component as Wall; hitWall.DamageWall(wallDamage); animator.SetTrigger("playerChop"); }
//OnCantMove overrides the abstract function OnCantMove in MovingObject. //It takes a generic parameter T which in the case of Player is a Wall which the player can attack and destroy. protected override void OnCantMove <T> (T component) { //Set hitWall to equal the component passed in as a parameter. Wall hitWall = component as Wall; //Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); }
//OnCantMove overrides the abstract function OnCantMove in MovingObject. //It takes a generic parameter T which in the case of Player is a Wall which the player can attack and destroy. protected override void OnCantMove <T> (T component) { Wall hitWall = component as Wall; //Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); //Set the attack trigger of the player's animation controller in order to play the player's attack animation. animator.SetTrigger("playerChop"); }
//OnCantMove overrides the abstract function OnCantMove in MovingObject. //It takes a generic parameter T which in the case of Player is a Wall which the player can attack and destroy. protected override void OnCantMove <T> (T component) { //Set hitWall to equal the component passed in as a parameter. Wall hitWall = component as Wall; hitWall.DamageWall(wallDamage); //Set the attack trigger of the player's animation controller in order to play the player's attack animation. animator.SetTrigger("playerChop"); }
//OnCantMove is called if Enemy attempts to move into a space occupied by a Player, it overrides the OnCantMove function of MovingObject //and takes a generic parameter T which we use to pass in the component we expect to encounter, in this case Player protected override void OnCantMove <T> (T component) { //Declare hitPlayer and set it to equal the encountered component. Wall hitPlayer = component as Wall; //Call the DamageWall function of playerDamage passing it playerDamage, the amount of foodpoints to be subtracted. hitPlayer.DamageWall(enemyAttackPoints); //Set the attack trigger of animator to trigger Enemy attack animation. animator.SetTrigger("attack"); }
//OnCantMoveは、MovingObjectのOnCantMoveという抽象関数をオーバーライドします。 //それはプレーヤーが攻撃で破壊することができる壁である場合、一般的なパラメータTをとります。 protected override void OnCantMove <T>(T component) { //パラメーターとして渡されたコンポーネントと等しくなるようにhitWallを設定します。 Wall hitWall = component as Wall; //私たちが襲っている壁のDamageWall機能を呼び出します。 hitWall.DamageWall(wallDamage); //プレイヤーの攻撃アニメーションを再生するために、プレイヤーのアニメーションコントローラーの攻撃トリガーを設定します。 animator.SetTrigger("playerChop"); }
//OnCantMove overrides the abstract function OnCantMove in MovingObject. //It takes a generic parameter T which in the case of Player is a Wall which the player can attack and destroy. protected override void OnCantMove <T> (T component) { //Set hitWall to equal the component passed in as a parameter. Wall hitWall = component as Wall; //Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); //Set the attack trigger of the player's animation controller in order to play the player's attack animation. animator.SetBool("Chop", true); }
//OnCantMove覆盖MovingObject中的抽象函数OnCantMove。 //它接受一个通用参数T,在玩家的情况下,它是玩家可以攻击和摧毁的一堵墙。 protected override void OnCantMove <T> (T component) { //设置hitWall等于作为参数传入的组件。 Wall hitWall = component as Wall; //调用正在撞击的墙壁的DamageWall函数。 hitWall.DamageWall(wallDamage); //设置玩家动画控制器的攻击触发,以播放玩家的攻击动画。 animator.SetTrigger("playerChop"); }
public void Attack <T>(T component) where T : Component { //Set hitWall to equal the component passed in as a parameter. if (component.transform.GetComponent <Wall>()) { Wall hitWall = component as Wall; //Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); } }
//重写了基类啥都没干的OnCantMove。 //传入泛型参数wall,玩家撞墙后自动攻击并摧毁。 //OnCantMove overrides the abstract function OnCantMove in MovingObject. //It takes a generic parameter T which in the case of Player is a Wall which the player can attack and destroy. protected override void OnCantMove <T> (T component) { //定义一个Wall对象并将它等于传入的墙对象。 //Set hitWall to equal the component passed in as a parameter. Wall hitWall = component as Wall; //调用墙本身的方法用于造成1点伤害。 //Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); //播放玩家攻击的动画 //Set the attack trigger of the player's animation controller in order to play the player's attack animation. animator.SetTrigger("playerChop"); }
//OnCantMove is called if Enemy attempts to move into a space occupied by a Player, it overrides the OnCantMove function of MovingObject //and takes a generic parameter T which we use to pass in the component we expect to encounter, in this case Player protected override void OnCantMove <T>(T component) { if (component is Player) { //Declare hitPlayer and set it to equal the encountered component. Player hitPlayer = component as Player; } if (component is Wall) { //Set hitWall to equal the component passed in as a parameter. Wall hitWall = component as Wall; //Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); } //Call the RandomizeSfx function of SoundManager passing in the two audio clips to choose randomly between. SoundManager.instance.RandomizeSfx(attackSound1, attackSound2); }
//OnCantMove overrides the abstract function OnCantMove in MovingObject. //It takes a generic parameter T which in the case of Player is a Wall which the player can attack and destroy. protected override void OnCantMove <T> (T component) { if (component.tag == "Wall") { //Set hitWall to equal the component passed in as a parameter. Wall hitWall = component as Wall; //Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); Debug.Log("WallDestroyed"); //Set the attack trigger of the player's animation controller in order to play the player's attack animation. animator.SetTrigger("playerChop"); } else { Enemy hitEnemy = component as Enemy; SoundManager.instance.RandomizeSfx(knifeSlash); hitEnemy.DamageEnemy(knifeDamage); } }
//OnCantMove overrides the abstract function OnCantMove in MovingObject. //It takes a generic parameter T which in the case of Player is a Wall which the player can attack and destroy. protected override void OnCantMove <T> (T component) { if (component is Wall) { //Set hitWall to equal the component passed in as a parameter. Wall hitWall = component as Wall; //Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); } if (component is Enemy) { Enemy hitEnemy = component as Enemy; hitEnemy.hp -= 1; } //Set the attack trigger of the player's animation controller in order to play the player's attack animation. animator.SetTrigger("playerChop"); }
protected override void OnCantMove(RaycastHit2D hit) { if (hit.transform.GetComponent <Wall>() != null) { //Set hitWall to equal the component passed in as a parameter. Wall hitWall = hit.transform.GetComponent <Wall>(); //Call the DamageWall function of the Wall we are hitting. hitWall.DamageWall(wallDamage); //Set the attack trigger of the player's animation controller in order to play the player's attack animation. animator.SetTrigger("playerChop"); } if (hit.transform.GetComponent <Enemy>() != null) { Enemy hitWall = hit.transform.GetComponent <Enemy>(); hitWall.DamageEnemy(wallDamage); animator.SetTrigger("playerChop"); } }
/*protected override void OnCantMove <T> (T component) * { * * * if (typeof(T)==typeof(Wall)) * { * //Debug.Log("hit"); * Wall hitWall = component as Wall; * hitWall.DamageWall(playerAttributes.attack); * animator.SetTrigger("playerHit"); * } * else * { * Enemy hitEnemy = component as Enemy; * hitEnemy.DamageEnemy(playerAttributes.attack); * animator.SetTrigger("playerChop"); * } * }*/ protected override void OnCantMove <T>(T component) { Vector3 component_postion = component.transform.position; float x = component_postion.x; float y = component_postion.y; //Debug.Log(x); //Debug.Log(y); Vector3 player_postion = GameObject.FindGameObjectWithTag("Player").transform.position; float a = player_postion.x; float b = player_postion.y; //Debug.Log(a); //Debug.Log(b); if (typeof(T) == typeof(Wall) && (x - a) >= 0) { Wall hitWall = component as Wall; hitWall.DamageWall(GameObject.Find("BattleAttack").GetComponent <GameControl>().attack); animator.SetTrigger("playerRightChop"); } else if (typeof(T) == typeof(Wall) && (x - a) < 0) { Wall hitWall = component as Wall; hitWall.DamageWall(GameObject.Find("BattleAttack").GetComponent <GameControl>().attack); animator.SetTrigger("playerHit"); } else if (x - a >= 0) { Enemy hitEnemy = component as Enemy; hitEnemy.DamageEnemy(GameObject.Find("BattleAttack").GetComponent <GameControl>().attack); animator.SetTrigger("playerRightHit"); } else { Enemy hitEnemy = component as Enemy; hitEnemy.DamageEnemy(GameObject.Find("BattleAttack").GetComponent <GameControl>().attack); animator.SetTrigger("playerChop"); } }
protected override void OnCantMove <T> (T component) { Wall hitWall = component as Wall; hitWall.DamageWall(wallDamage); }