public void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.layer == 10 && heathlock == false) { GameObject.Find("SoundEffects").GetComponent <Audio>().PlaySound(0); Player2Move player2move = col.gameObject.GetComponent <Player2Move>(); player2move.playerhealth += HealthIncrease; if (player2move.playerhealth == 100) { P2healthBar.GetComponent <RectTransform>().sizeDelta = new Vector3((player2move.playerhealth * 590 / 100), 50); // Adjusts the healthbar rect size to mathch player health percentage } Destroy(this.gameObject); } if (col.gameObject.layer == 9 && heathlock == false) { GameObject.Find("SoundEffects").GetComponent <Audio>().PlaySound(0); Player1Move player1move = col.gameObject.GetComponent <Player1Move>(); player1move.playerhealth += HealthIncrease; if (player1move.playerhealth == 100) { P1healthBar.GetComponent <RectTransform>().sizeDelta = new Vector3((player1move.playerhealth * 590 / 100), 50); // Adjusts the healthbar rect size to mathch player health percentage } Destroy(this.gameObject); } }
//Punch Code private void DetectPunchCode(Collider2D collision) { if (Input.GetButtonDown("J2_Punch") && !Stunned2) { bool OtherPlayerStunned; if (collision.gameObject.tag == "P1LT") { //corresponding animation OtherPlayerStunned = collision.gameObject.GetComponentInParent <DetectFoodType>().Stunned; if (OtherPlayerStunned == false) { Player1Move P1M = collision.gameObject.GetComponentInParent <Player1Move>(); animator.SetBool("Punch2Left", true); P1M.P1WasPunched(); //PunchFinished = false; StartCoroutine("PunchOver2"); // Debug.Log("Player 2 Has Punched Player 1's Left Side!"); } } else if (collision.gameObject.tag == "P1RT") { OtherPlayerStunned = collision.gameObject.GetComponentInParent <DetectFoodType>().Stunned; if (OtherPlayerStunned == false) { Player1Move P1M = collision.gameObject.GetComponentInParent <Player1Move>(); animator.SetBool("Punch2Right", true); P1M.P1WasPunched(); //PunchFinished = false; StartCoroutine("PunchOver2"); // Debug.Log("Player 2 Has Punched Player 1's Right Side!"); //coresponding animation } } } }
// Start is called before the first frame update void Start() { SocketManger.Socket.On("sendTomove1", (data) => { string json = JsonConvert.SerializeObject(data.Json.args[0]); Player1Move response = JsonUtility.FromJson <Player1Move>(json); x = response.x; y = response.y; check = true; }); }
void OnCollisionEnter2D(Collision2D col) { if (col.gameObject.layer == 9) { Debug.Log("P1 Hit"); Player1Move player1move = col.gameObject.GetComponent <Player1Move>(); player1move.playerhealth -= damage; healthBar.GetComponent <RectTransform>().sizeDelta = new Vector3((player1move.playerhealth * 590 / 100), 50); // Adjusts the healthbar rect size to mathch player health percentage (Michael) Destroy(this.gameObject); //GetComponent<Audio>().PlaySound(1); } if (col.gameObject.layer == 12) { Destroy(this.gameObject); } }
public void OnTriggerEnter2D(Collider2D col) { if (col.gameObject.layer == 9) { GameObject.Find("SoundEffects").GetComponent <Audio>().PlaySound(0); player1move = col.gameObject.GetComponent <Player1Move>(); StartCoroutine(P1FR_Powerup()); //this.gameObject.SetActive(false); Destroy(this.gameObject); } if (col.gameObject.layer == 10) { GameObject.Find("SoundEffects").GetComponent <Audio>().PlaySound(0); player2move = col.gameObject.GetComponent <Player2Move>(); StartCoroutine(P2FR_Powerup()); //this.gameObject.SetActive(false); Destroy(this.gameObject); } }
// Use this for initialization void Start() { AudioObject.clip = StartRound; AudioObject.Play(); Screen.SetResolution(1920, 1080, true); P1ScoreCoins = new GameObject[2]; P2ScoreCoins = new GameObject[2]; P1Score = 0; P2Score = 0; Customer = GameObject.FindGameObjectWithTag("Customer"); Customers = Resources.LoadAll <Sprite>("Sprites/Customers"); SetCoinArrays(); Set(); Goal = GameObject.FindGameObjectWithTag("FoodGoal").GetComponent <ChooseRandomFood>(); fa = GameObject.FindGameObjectWithTag("SpawnManager").GetComponent <Falling>(); GameObject Player1 = GameObject.Find("Player1"); GameObject Player2 = GameObject.Find("Player2"); P1 = Player1.GetComponent <Player1Move>(); P2 = Player2.GetComponent <Player2Move>(); DFTP1 = Player1.GetComponent <DetectFoodType>(); DFTP2 = Player2.GetComponent <DetectFoodType>(); }
// Update is called once per frame void Update() { //プレイヤーがnullでなければPlayer1Moveを取得 if (player1 != null) { player1Move = player1.GetComponent <Player1Move>(); } if (player2 != null) { player2Move = player2.GetComponent <Player2Move>(); } //移動量を初期化 player1_xy = Vector2.zero; player2_xy = Vector2.zero; //一定条件で入力を受け付けない if ((p1_isRotate == true || p2_isRotate == true) || Pause.pause == true || (Player1Move.isDropDown == true) || (Player2Move.isDropDown == true) || CsvMessage.startend == false) { if (Pause.pause == false) { Pause.rotate = true; } isNotInput = true; inputX = 0; inputY = 0; } else if ((EnemyHit.isGameClear == false) && (EnemyHit.isGameOver == false) && (p1_isRotate == false && p2_isRotate == false) && (isTweenMove == false) && Pause.pause == false ) { Pause.rotate = false; isNotInput = false; } //入力可能なら if (isNotInput == false) { //各入力方向の取得 if (Input.GetAxisRaw("Horizontal") >= 0.5) { inputX = 1; inputY = 0; } else if (Input.GetAxisRaw("Horizontal") <= -0.5f) { inputX = -1; inputY = 0; } else if (Input.GetAxisRaw("Vertical") >= 0.5f) { inputY = 1; inputX = 0; } else if (Input.GetAxisRaw("Vertical") <= -0.5f) { inputY = -1; inputX = 0; } else { inputX = 0; inputY = 0; } /********Player1の入力処理****************/ //右方向入力時に障害物に触れていなければ if (player1Move.isStopRight == false && inputX >= 1f) { //ターゲットを挟めむ条件がそろっていれば if ((player1Move.enemyForwerd == true) && (player2Move.enemyBack == true) && (player1Move.colorCheck == player2Move.colorCheck)) { //挟むアニメーション処理 isNotInput = true; isTweenMove = true; LeanTween.moveZ(player1, player1.transform.position.z + 0.5f, tweenTime).setOnComplete(TweenRightEnd); } else { player1_xy = new Vector2(1, 0); } } //左方向入力時に障害物に触れていなければ if (player1Move.isStopLeft == false && inputX <= -1f) { //ターゲットを挟めむ条件がそろっていれば if ((player1Move.enemyBack == true) && (player2Move.enemyForward == true) && (player1Move.colorCheck == player2Move.colorCheck)) { //挟むアニメーション処理 isNotInput = true; isTweenMove = true; LeanTween.moveZ(player1, player1.transform.position.z - 0.5f, tweenTime).setOnComplete(TweenLeftEnd); } else { player1_xy = new Vector2(-1, 0); } } //xに入力が入っていなければ if (player1_xy.x == 0) { //上方向入力時に障害物に触れていなければ if (player1Move.isStopUp == false && inputY >= 1f) { //ターゲットを挟めむ条件がそろっていれば if ((player1Move.enemyLeft == true) && (player2Move.enemyRight == true) && (player1Move.colorCheck == player2Move.colorCheck)) { //挟むアニメーション処理 isNotInput = true; isTweenMove = true; LeanTween.moveX(player1, player1.transform.position.x - 0.5f, tweenTime).setOnComplete(TweenUpEnd); } else { player1_xy = new Vector2(0, 1); } } //下方向入力時に障害物に触れていなければ if (player1Move.isStopDown == false && inputY <= -1f) { //ターゲットを挟めむ条件がそろっていれば if ((player1Move.enemyRight == true) && (player2Move.enemyLeft == true) && (player1Move.colorCheck == player2Move.colorCheck)) { //挟むアニメーション処理 isNotInput = true; isTweenMove = true; LeanTween.moveX(player1, player1.transform.position.x + 0.5f, tweenTime).setOnComplete(TweenDownEnd); } else { player1_xy = new Vector2(0, -1); } } } /**********Player2の入力処理******************/ if (player2Move.isStopLeft == false && inputX >= 1f) { if ((player2Move.enemyBack == true) && (player1Move.enemyForwerd == true) && (player1Move.colorCheck == player2Move.colorCheck)) { isNotInput = true; isTweenMove = true; LeanTween.moveZ(player2, player2.transform.position.z - 0.5f, tweenTime); } else { player2_xy = new Vector2(-1, 0); } } if (player2Move.isStopRight == false && inputX <= -1f) { if ((player2Move.enemyForward == true) && (player1Move.enemyBack == true) && (player1Move.colorCheck == player2Move.colorCheck)) { isNotInput = true; isTweenMove = true; LeanTween.moveZ(player2, player2.transform.position.z + 0.5f, tweenTime); } else { player2_xy = new Vector2(1, 0); } } if (player2_xy.x == 0) { if (player2Move.isStopUp == false && inputY <= -1f) { if ((player2Move.enemyLeft == true) && (player1Move.enemyRight == true) && (player1Move.colorCheck == player2Move.colorCheck)) { isNotInput = true; isTweenMove = true; LeanTween.moveX(player2, player2.transform.position.x - 0.5f, tweenTime); } else { player2_xy = new Vector2(0, 1); } } if (player2Move.isStopDown == false && inputY >= 1f) { if ((player2Move.enemyRight == true) && (player1Move.enemyLeft == true) && (player1Move.colorCheck == player2Move.colorCheck)) { isNotInput = true; isTweenMove = true; LeanTween.moveX(player2, player2.transform.position.x + 0.5f, tweenTime); } else { player2_xy = new Vector2(0, -1); } } } } //プレイヤー1の回転処理 if ((player1_xy.x != 0 || player1_xy.y != 0) && p1_isRotate == false) { p1_directionX = player1_xy.y; // 回転方向セット (x,yどちらかは必ず0) p1_directionZ = player1_xy.x; // 回転方向セット (x,yどちらかは必ず0) p1_startPos = player1.transform.position; // 回転前の座標を保持 p1_fromRotation = player1.transform.rotation; // 回転前のクォータニオンを保持 player1.transform.Rotate(p1_directionZ * 90, 0, p1_directionX * 90, Space.World); // 回転方向に90度回転させる p1_toRotation = player1.transform.rotation; // 回転後のクォータニオンを保持 player1.transform.rotation = p1_fromRotation; // CubeのRotationを回転前に戻す。(transformのシャローコピーとかできないんだろうか…。) p1_rotationTime = 0; // 回転中の経過時間を0に。 p1_isRotate = true; // 回転中フラグをたてる。 } //プレイヤー2の回転処理 if ((player2_xy.x != 0 || player2_xy.y != 0) && p2_isRotate == false) { p2_directionX = player2_xy.y; // 回転方向セット (x,yどちらかは必ず0) p2_directionZ = player2_xy.x; // 回転方向セット (x,yどちらかは必ず0) p2_startPos = player2.transform.position; // 回転前の座標を保持 p2_fromRotation = player2.transform.rotation; // 回転前のクォータニオンを保持 player2.transform.Rotate(p2_directionZ * 90, 0, p2_directionX * 90, Space.World); // 回転方向に90度回転させる p2_toRotation = player2.transform.rotation; // 回転後のクォータニオンを保持 player2.transform.rotation = p2_fromRotation; // CubeのRotationを回転前に戻す。(transformのシャローコピーとかできないんだろうか…。) p2_rotationTime = 0; // 回転中の経過時間を0に。 p2_isRotate = true; // 回転中フラグをたてる。 } }
// Use this for initialization void Start() { Character = GetComponent <Rigidbody2D>(); thePlayer = GameObject.Find("Character"); play1move = thePlayer.GetComponent <Player1Move>(); //Refferences the script }