//玩家死亡 public void PlayerDead() { _effectSound.PlayEffectSound(EffectSound.BOOM); Renderer rend = this.gameObject.GetComponent <Renderer>(); rend.material.color = Color.white; transform.FindChild("Eff_Burst_2_oneShot").gameObject.SetActive(true); if (IsWinLoseImageDown == false) { _WinLoseImageManage.GetComponent <ObjectMoveInEffect>().SmoothMoveInButtonEffect(); Sprite spr = Resources.Load <Sprite>("Lose"); _WinLoseImage.GetComponent <Image>().sprite = spr; IsWinLoseImageDown = true; } //rend.material.shader = Shader.Find("02 - Default"); //rend.material.SetColor("MainColor", Color.blue); }
void OnTriggerEnter(Collider other) { //碰撞目標事件 if (other.gameObject.tag == "TargetObject") { Destroy(this.gameObject); _effectSound.PlayEffectSound(EffectSound.BOOM); other.transform.FindChild("Eff_Burst_2_oneShot").gameObject.SetActive(true); //Destroy(this.gameObject); //到下一關的事件 _winLoseEvent.WinEvent(); //Debug.Log("撞到目標物"); } //碰撞黑洞事件 if (other.gameObject.tag == "BlackHoleObject") { Debug.Log("enter blackhole"); Vector3 blackHoleForce = new Vector3((other.transform.position.x - this.gameObject.transform.position.x) * 300, (other.transform.position.y - this.gameObject.transform.position.y) * 300, 0); this.GetComponent <ConstantForce>().force = blackHoleForce; } //碰撞白洞事件 if (other.gameObject.tag == "WhiteHoleObject") { Vector3 whiteHoleForce = new Vector3((other.transform.position.x - this.gameObject.transform.position.x) * -300, (other.transform.position.y - this.gameObject.transform.position.y) * -300, 0); this.GetComponent <ConstantForce>().force = whiteHoleForce; } if (other.gameObject.tag == "SeparateObject") { if (other.GetComponent <SeparateObject>().TriggerEvent()) { //修改物體速度(根據vector3) //入射向量 Vector3 originVelocity = _ballRigidbody.velocity; Vector3 verticalVelocity1 = new Vector3(); Vector3 verticalVelocity2 = new Vector3(); this.GetTwoVerticalVector(originVelocity, ref verticalVelocity1, ref verticalVelocity2); verticalVelocity1 = this.GetShiftPosition(verticalVelocity1, this.gameObject.GetComponent <RectTransform>().rect.width / 5); verticalVelocity2 = this.GetShiftPosition(verticalVelocity2, this.gameObject.GetComponent <RectTransform>().rect.width / 5); GameObject cloneLaserBall1 = (GameObject)Instantiate(this.gameObject, new Vector3(this.transform.position.x + verticalVelocity1.x, this.transform.position.y + verticalVelocity1.y, this.transform.position.z), new Quaternion(0, 0, 0, 1) ); cloneLaserBall1.GetComponent <Rigidbody>().velocity = Quaternion.Euler(0, 0, 10) * originVelocity; cloneLaserBall1.transform.localScale = this.gameObject.transform.lossyScale; cloneLaserBall1.transform.SetParent(this.transform.parent); GameObject cloneLaserBall2 = (GameObject)Instantiate(this.gameObject, new Vector3(this.transform.position.x + verticalVelocity2.x, this.transform.position.y + verticalVelocity2.y, this.transform.position.z), new Quaternion(0, 0, 0, 1) ); cloneLaserBall2.GetComponent <Rigidbody>().velocity = Quaternion.Euler(0, 0, -10) * originVelocity; cloneLaserBall2.transform.localScale = this.gameObject.transform.lossyScale; cloneLaserBall2.transform.SetParent(this.transform.parent); } } if (other.gameObject.tag == "TransmissionObject") { if (other.GetComponent <TransmissionObject>().CanMoveToAnotherSidePortal()) { this.transform.position = other.GetComponent <TransmissionObject>().ReturnAnotherSidePortalPosition(); } } //吃到nuff道具 if (other.gameObject.tag == "buffObject") { Transform TargetFightObjects = transform.root.Find("/GameLevelObjects/InLevelObjects/TargetFightObjects(Clone)"); if (_whichPlayerBall == "right") { playerCube targetObjectRight = TargetFightObjects.FindChild("targetObjectLeft").transform.GetComponent <playerCube>(); Debug.Log(targetObjectRight); if (targetObjectRight.PlayerBuffNerf == -1)//有nerf則清除再蓋過去 { targetObjectRight.clearPlaterBuffNerf(); } if (targetObjectRight.PlayerBuffNerf == 0) { targetObjectRight.setPlayerBuff(); } } else if (_whichPlayerBall == "left") { playerCube targetObjectLeft = TargetFightObjects.FindChild("targetObjectRight").transform.GetComponent <playerCube>(); if (targetObjectLeft.PlayerBuffNerf == -1)//有nerf則清除再蓋過去 { targetObjectLeft.clearPlaterBuffNerf(); } if (targetObjectLeft.PlayerBuffNerf == 0) { targetObjectLeft.setPlayerBuff(); } } other.gameObject.transform.parent.GetComponent <BuffNerfGenerator>().ClearTimer(); Destroy(other.gameObject); } //吃到nerf道具 if (other.gameObject.tag == "nerfObject") { Transform TargetFightObjects = transform.root.Find("/GameLevelObjects/InLevelObjects/TargetFightObjects(Clone)"); if (_whichPlayerBall == "right") { playerCube targetObjectRight = TargetFightObjects.FindChild("targetObjectLeft").transform.GetComponent <playerCube>(); if (targetObjectRight.PlayerBuffNerf == 1)//有buff則清除再蓋過去 { targetObjectRight.clearPlaterBuffNerf(); } if (targetObjectRight.PlayerBuffNerf == 0) { targetObjectRight.setPlayerNerf(); } } else if (_whichPlayerBall == "left") { playerCube targetObjectLeft = TargetFightObjects.FindChild("targetObjectRight").transform.GetComponent <playerCube>(); if (targetObjectLeft.PlayerBuffNerf == 1)//有buff則清除再蓋過去 { targetObjectLeft.clearPlaterBuffNerf(); } if (targetObjectLeft.PlayerBuffNerf == 0) { targetObjectLeft.setPlayerNerf(); } } other.gameObject.transform.parent.GetComponent <BuffNerfGenerator>().ClearTimer(); Destroy(other.gameObject); } }