//OnCantMoveは、MovingObjectのOnCantMoveという抽象関数をオーバーライドします。 //それはプレーヤーが攻撃で破壊することができる壁である場合、一般的なパラメータTをとります。 //MovingObject.AttemptMove でhitしたcomponentを取得 protected override void OnCantMove <T>(T component) { if (component.tag == "Wall") { //引数のcomponentをhitWallに代入 Wall hitWall = component as Wall; //襲っている壁のDamageWall機能を呼び出します。 hitWall.DamageWall(wallDamage); //プレイヤーの攻撃アニメーションを再生するために、プレイヤーのアニメーションコントローラーの攻撃トリガーを設定します。 animator.SetTrigger("playerChop"); } else if (component.tag == "Enemy") { //引数のcomponentをhitEnemyに代入 Enemy hitEnemy = component as Enemy; //DamageEnemy機能を呼び出します。 hitEnemy.DamageEnemy(wallDamage); //プレイヤーの攻撃アニメーションを再生するために、プレイヤーのアニメーションコントローラーの攻撃トリガーを設定します。 animator.SetTrigger("playerChop"); } else if (component.tag == "Exit") { //引数のcomponentをhitEnemyに代入 ClearExit clearExit = component as ClearExit; //DamageEnemy機能を呼び出します。 clearExit.ExitClear(); } }
//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); 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.SetTrigger ("playerChop"); if (component is Enemy) { Enemy enemy = component as Enemy; enemy.DamageEnemy(enemyDamage, transform); animator.SetTrigger("playerChop"); } if (component is Wall) { 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 = null; Enemy hitEnemy = null; //Call the DamageWall function of the Wall we are hitting. if (component is Wall) { Debug.Log("Hit Wall"); hitWall = component as Wall; } else if (component is Enemy) { Debug.Log("Hit Enemy"); hitEnemy = component as Enemy; } if (hitWall != null) { hitWall.DamageWall(wallDamage); } if (hitEnemy != null) { Debug.Log("HIT!"); hitEnemy.DamageEnemy(attackDamage); } //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(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); } }
protected void onShoot <T>(T component) { ammoText.text = "Ammo: " + ammo; blockingText.enabled = false; Enemy hitEnemy = component as Enemy; SoundManager.instance.RandomizeSfx(gunShot); hitEnemy.DamageEnemy(gunDamage); }
//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. Enemy attackenemy = component as Enemy; Debug.Log("attack"); //Call the DamageWall function of the Wall we are hitting. attackenemy.DamageEnemy(attack); Debug.Log("ruattacking"); //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 enemyHit <T> (T component) { Enemy hit = component as Enemy; //Set hitWall to equal the component passed in as a parameter. //Wall hitWall = component as Wall; String tag = component.tag; scoreText.text = "Score: " + score; hit.DamageEnemy(damage); //foodText.text = "tester"; //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) { 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); } }
//Move returns true if it is able to move and false if not. //Move takes parameters for x direction, y direction and a RaycastHit2D to check collision. protected override bool Move(int xDir, int yDir, out RaycastHit2D hit) { //Store start position to move from, based on objects current transform position. Vector2 start = transform.position; // Calculate end position based on the direction parameters passed in when calling Move. Vector2 end = start + new Vector2(xDir, yDir); //Disable the boxCollider so that linecast doesn't hit this object's own collider. boxCollider.enabled = false; //Cast a line from start point to end point checking collision on blockingLayer. hit = Physics2D.Linecast(start, end, blockingLayer); //Re-enable boxCollider after linecast boxCollider.enabled = true; if (hit.transform != null && hit.transform.tag == "Enemy" && !isMoving) { Enemy enemy = hit.transform.GetComponent <Enemy>(); enemy.DamageEnemy(attack); return(true); } //Check if anything was hit if (hit.transform == null && !isMoving) { //placing the moving marker movingMarker.SetActive(true); movingMarker.transform.position = new Vector3(end.x, end.y, 0); //If nothing was hit, start SmoothMovement co-routine passing in the Vector2 end as destination StartCoroutine(SmoothMovement(end)); //Return true to say that Move was successful return(true); } //If something was hit, return false, Move was unsuccesful. return(false); }
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"); } }