private void OnTriggerEnter2D(Collider2D coll) { if (coll.tag == "Arrow") { enemyHp -= LobbySceneBtnScript.Instance().basicDamage; if (enemyHp <= 0) { //LobbySceneBtnScript.Instance().myScore += score; Instantiate(dieEffect, transform.position, transform.rotation); Destroy(gameObject); GameObject obj1 = Instantiate(enemyChange) as GameObject; obj1.transform.position = transform.position; obj1.GetComponent <Rigidbody2D>().velocity = new Vector2(-enemyMove, 0); GameObject obj2 = Instantiate(enemyChange) as GameObject; obj2.transform.position = transform.position; obj2.GetComponent <Rigidbody2D>().velocity = new Vector2(enemyMove, 0); } } if (coll.tag == "Charge50Attack") { enemyHp -= (LobbySceneBtnScript.Instance().basicDamage + LobbySceneBtnScript.Instance().chargeDamage); if (enemyHp <= 0) { //LobbySceneBtnScript.Instance().myScore += score; Instantiate(dieEffect, transform.position, transform.rotation); Destroy(gameObject); GameObject obj1 = Instantiate(enemyChange) as GameObject; obj1.transform.position = transform.position; obj1.GetComponent <Rigidbody2D>().velocity = new Vector2(-enemyMove, 0); GameObject obj2 = Instantiate(enemyChange) as GameObject; obj2.transform.position = transform.position; obj2.GetComponent <Rigidbody2D>().velocity = new Vector2(enemyMove, 0); } } if (coll.tag == "Charge100Attack") { enemyHp -= LobbySceneBtnScript.Instance().basicDamage + (LobbySceneBtnScript.Instance().chargeDamage * 2); if (enemyHp <= 0) { //LobbySceneBtnScript.Instance().myScore += score; Instantiate(dieEffect, transform.position, transform.rotation); Destroy(gameObject); GameObject obj1 = Instantiate(enemyChange) as GameObject; obj1.transform.position = transform.position; obj1.GetComponent <Rigidbody2D>().velocity = new Vector2(-enemyMove, 0); GameObject obj2 = Instantiate(enemyChange) as GameObject; obj2.transform.position = transform.position; obj2.GetComponent <Rigidbody2D>().velocity = new Vector2(enemyMove, 0); } } }
void Start() { if (_instance == null) { _instance = this; } //shotDelay = 1; playerHp = LobbySceneBtnScript.Instance().playerMaxHp; // 인스턴스와 같다고 해줘야 업그레이드시 정보 넘어옴 playerMaxHp = LobbySceneBtnScript.Instance().playerMaxHp; EnemyStateDamage(); StageObject(); }
public void UsePotionBtnClick() { if (pausePopUpCheck.activeSelf == true && exitLobbyCheck.activeSelf == false && winPopUp.activeSelf == false) { if (LobbySceneBtnScript.Instance().myPotion >= 1) { if (playerHp > 0 && playerHp != LobbySceneBtnScript.Instance().playerMaxHp) { playerHp += 1; LobbySceneBtnScript.Instance().myPotion -= 1; } if (playerHp >= LobbySceneBtnScript.Instance().playerMaxHp) { playerHp = LobbySceneBtnScript.Instance().playerMaxHp; } } } }
void Update() { ShotDelay(); curPlayerHp = playerHp / playerMaxHp; // hp,max 만든 다음 -> ( /5(playerMaxHp) ) = hp수치를 써주면 됌. 프로그레스바 벨류가 1이므로 비율을 맞추기위해 나누기5 해줌 hpBar.value = curPlayerHp; ChargeGageBar(); // 업데이트가 길면 안되므로 함수로 만들어서 적으면 정상 작동 함 PlayerMoveLimit(); // 업데이트가 길면 안되므로 함수로 만들어서 적으면 정상 작동 함 hpLabel.text = "HP : " + playerHp.ToString(); haveGem.text = LobbySceneBtnScript.Instance().myGem.ToString(); haveGold.text = LobbySceneBtnScript.Instance().myGold.ToString(); havePotion.text = LobbySceneBtnScript.Instance().myPotion.ToString(); //nowSocer.text = "Score : " + LobbySceneBtnScript.Instance().myScore.ToString(); //bestScore.text = "3rd Score : " + LobbySceneBtnScript.Instance().thirdScore.ToString(); //bestScore.text = scoreBest.ToString(); //if (scoreBest > LobbySceneBtnScript.Instance().thirdScore) //{ // bestScore.text = "2nd Score : " + LobbySceneBtnScript.Instance().secondScore.ToString(); //} //if (scoreBest > LobbySceneBtnScript.Instance().secondScore) //{ // bestScore.text = "1st Score : " + LobbySceneBtnScript.Instance().bestScore.ToString(); //} if (chargeEffect.activeSelf == true) { chargeGage += Time.deltaTime; if (chargeGage > chargeMax) { chargeGage = chargeMax; if (chargeGage == chargeMax) { chargeGageBool = true; } } } //if (transform.position.y < -2.5f) //// 플레이어 높이 제한 ( 맨위에 둬야는 이유는 함수로 사용 안할 시 업데이트는 순서대로 돌아가므로 자 객체인 firepos의 월드포지션이 계속 내려감 //{ // transform.position = new Vector2(transform.position.x, -2.5f); //} if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) { if (pausePopUpCheck.activeSelf == true && exitLobbyCheck.activeSelf == false) { Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition; transform.Translate(touchDeltaPosition.x * Time.deltaTime, 0, 0); if (gameObject.transform.position.x < 0) { GetComponent <Animator>().Play("left"); } if (gameObject.transform.position.x >= 0) { GetComponent <Animator>().Play("right"); } } } if (Input.GetKey(KeyCode.LeftArrow)) { if (pausePopUpCheck.activeSelf == true && exitLobbyCheck.activeSelf == false) { GetComponent <Animator>().Play("left"); transform.Translate(-playerSpeed * Time.deltaTime, 0, 0); } } else { playerAnim.SetBool("Left Bool", false); } if (Input.GetKey(KeyCode.RightArrow)) { if (pausePopUpCheck.activeSelf == true && exitLobbyCheck.activeSelf == false) { GetComponent <Animator>().Play("right"); transform.Translate(playerSpeed * Time.deltaTime, 0, 0); } } else { playerAnim.SetBool("Right Bool", false); } if (Input.GetKeyDown(KeyCode.Space)) // 이 밑 로직들은 제자리 공격시 캐릭터 x값에 따라 다른 모션을 취하기 위한 로직 { if (pausePopUpCheck.activeSelf == true && exitLobbyCheck.activeSelf == false) { //ArrowFire(); // 발사 함수 불러오기 //*firePos.GetComponent<FireScript>().Fire(); // fireScript에서 fire 함수 불러오기 if (gameObject.transform.position.x < 0) { playerAnim.SetBool("Left Bool", true); if (shotDelay <= 0) { firePos.GetComponent <FireScript>().Fire(); // fireScript에서 fire 함수 불러오기 shotDelay = shotCool; } } if (gameObject.transform.position.x >= 0) { playerAnim.SetBool("Right Bool", true); if (shotDelay <= 0) { firePos.GetComponent <FireScript>().Fire(); shotDelay = shotCool; } } } } if (Input.GetKeyDown(KeyCode.Space) && Input.GetKey(KeyCode.RightArrow)) // 이 밑 로직들은 캐릭터 좌,우 이동시 기존 모션과 반대로 공격모션 취하기 위한 로직 { if (pausePopUpCheck.activeSelf == true && exitLobbyCheck.activeSelf == false) { GetComponent <Animator>().Play("right"); if (shotDelay <= 0) { firePos.GetComponent <FireScript>().Fire(); shotDelay = shotCool; } } } if (Input.GetKeyDown(KeyCode.Space) && Input.GetKey(KeyCode.LeftArrow)) { if (pausePopUpCheck.activeSelf == true && exitLobbyCheck.activeSelf == false) { GetComponent <Animator>().Play("left"); if (shotDelay <= 0) { firePos.GetComponent <FireScript>().Fire(); shotDelay = shotCool; } } } if (Input.GetKey(KeyCode.Space)) // 챠지 어택 게이지 모으기 , 스페이스 누르고 있으면 { if (pausePopUpCheck.activeSelf == true && exitLobbyCheck.activeSelf == false) { chargeEffect.SetActive(true); } } if (Input.GetKeyUp(KeyCode.Space)) // 챠지 어택 , 스페이스 손 떼면 { if (pausePopUpCheck.activeSelf == true && exitLobbyCheck.activeSelf == false) { if (gameObject.transform.position.x < 0) { playerAnim.SetBool("Left Bool", true); if (chargeGage >= chargeMax && chargeGageBool == true) { Debug.Log("chargeMax"); firePos.GetComponent <FireScript>().Charge100Attack(); chargeGage = 0; chargeEffect.SetActive(false); } else { chargeGage = 0; chargeEffect.SetActive(false); } if (chargeBar.value > 0.5 && chargeBar.value < 1.0) { Debug.Log("chargeMiddle"); firePos.GetComponent <FireScript>().Charge50Attack(); chargeGage = 0; chargeGageBool = false; chargeEffect.SetActive(false); } else { chargeGage = 0; chargeGageBool = false; chargeEffect.SetActive(false); } } } if (gameObject.transform.position.x >= 0) { if (pausePopUpCheck.activeSelf == true && exitLobbyCheck.activeSelf == false) { playerAnim.SetBool("Right Bool", true); if (chargeGage >= chargeMax && chargeGageBool == true) { Debug.Log("chargeMax"); firePos.GetComponent <FireScript>().Charge100Attack(); chargeGage = 0; chargeEffect.SetActive(false); } else { chargeGage = 0; chargeEffect.SetActive(false); } if (chargeBar.value > 0.5 && chargeBar.value < 1.0) { Debug.Log("chargeMiddle"); firePos.GetComponent <FireScript>().Charge50Attack(); chargeGage = 0; chargeGageBool = false; chargeEffect.SetActive(false); } else { chargeGage = 0; chargeGageBool = false; chargeEffect.SetActive(false); } } } } //if (transform.position.x > limtX) // 좌,우 이동 제한 //{ // transform.position = new Vector2(limtX, transform.position.y); //} //if (transform.position.x < -limtX) //{ // transform.position = new Vector2(-limtX, transform.position.y); //} //Debug.Log(firePos.transform.position); if (AttackedVelocityTime == true) // 몬스터에게 넉백 당하고 멈추기 위한 bool { timeA += Time.deltaTime; if (timeA > timeB) { timeA = 0; AttackedVelocityTime = false; } if (AttackedVelocityTime == false) { //Debug.Log("2"); rb2D.velocity = new Vector2(0, 0); } } }
private void OnTriggerEnter2D(Collider2D other) { //파랑한테 맞았을때 if (other.tag == "BlueEnemy" && !isUnBeatTime)// 코루틴 false, 적과 부딪혔을시 ( 코루틴 실행시 hp 안닳게 하기위해 && ! 사용) { playerHp -= enemyStateDam[0]; if (playerHp >= 1) { //LobbySceneBtnScript.Instance().myScore -= score; isUnBeatTime = true; StartCoroutine("UnBeatTime"); } AttackedVelocityTime = true; if (AttackedVelocityTime == true) { //Vector2 attackVel = Vector2.zero; //Debug.Log("1"); if (other.gameObject.transform.position.x > transform.position.x) // 밀림 효과 { rb2D.velocity = new Vector2(-10f, 5f); } else { rb2D.velocity = new Vector2(10f, 5f); } //{ // attackVel = new Vector2(-10f, 5f); //} //else //{ // attackVel = new Vector2(10f, 5f); //} //rb2D.AddForce(attackVel, ForceMode2D.Impulse); } } //빨강한테 맞았을때 if (other.tag == "RedEnemy" && !isUnBeatTime)// 코루틴 false, 적과 부딪혔을시 ( 코루틴 실행시 hp 안닳게 하기위해 && ! 사용) { playerHp -= enemyStateDam[1]; if (playerHp >= 1) { //LobbySceneBtnScript.Instance().myScore -= score; isUnBeatTime = true; StartCoroutine("UnBeatTime"); } AttackedVelocityTime = true; if (AttackedVelocityTime == true) { //Vector2 attackVel = Vector2.zero; //Debug.Log("1"); if (other.gameObject.transform.position.x > transform.position.x) // 밀림 효과 { rb2D.velocity = new Vector2(-10f, 5f); } else { rb2D.velocity = new Vector2(10f, 5f); } //{ // attackVel = new Vector2(-10f, 5f); //} //else //{ // attackVel = new Vector2(10f, 5f); //} //rb2D.AddForce(attackVel, ForceMode2D.Impulse); } } //검정한테 맞았을때 if (other.tag == "BlackEnemy" && !isUnBeatTime)// 코루틴 false, 적과 부딪혔을시 ( 코루틴 실행시 hp 안닳게 하기위해 && ! 사용) { playerHp -= enemyStateDam[2]; if (playerHp >= 1) { //LobbySceneBtnScript.Instance().myScore -= score; isUnBeatTime = true; StartCoroutine("UnBeatTime"); } AttackedVelocityTime = true; if (AttackedVelocityTime == true) { //Vector2 attackVel = Vector2.zero; //Debug.Log("1"); if (other.gameObject.transform.position.x > transform.position.x) // 밀림 효과 { rb2D.velocity = new Vector2(-10f, 5f); } else { rb2D.velocity = new Vector2(10f, 5f); } //{ // attackVel = new Vector2(-10f, 5f); //} //else //{ // attackVel = new Vector2(10f, 5f); //} //rb2D.AddForce(attackVel, ForceMode2D.Impulse); } } //하얀한테 맞았을때 if (other.tag == "WhiteEnemy" && !isUnBeatTime)// 코루틴 false, 적과 부딪혔을시 ( 코루틴 실행시 hp 안닳게 하기위해 && ! 사용) { playerHp -= enemyStateDam[3]; if (playerHp >= 1) { //LobbySceneBtnScript.Instance().myScore -= score; isUnBeatTime = true; StartCoroutine("UnBeatTime"); } AttackedVelocityTime = true; if (AttackedVelocityTime == true) { //Vector2 attackVel = Vector2.zero; //Debug.Log("1"); if (other.gameObject.transform.position.x > transform.position.x) // 밀림 효과 { rb2D.velocity = new Vector2(-10f, 5f); } else { rb2D.velocity = new Vector2(10f, 5f); } //{ // attackVel = new Vector2(-10f, 5f); //} //else //{ // attackVel = new Vector2(10f, 5f); //} //rb2D.AddForce(attackVel, ForceMode2D.Impulse); } } if (playerHp <= 0) { Instantiate(dieEffect, transform.position, transform.rotation); losePopUp.SetActive(true); // 팝업은 켜지지만 플레이어 파괴라서 보상이 실시간으로 보이지 않음. 되도록이면 다른곳에 달아줄거나 밑에처럼 한번더 써줄것 LobbySceneBtnScript.Instance().myGold += 100; LobbySceneBtnScript.Instance().myPotion += 35; haveGold.text = LobbySceneBtnScript.Instance().myGold.ToString(); havePotion.text = LobbySceneBtnScript.Instance().myPotion.ToString(); hpLabel.text = "HP : 0"; hpBar.value = 0; Destroy(gameObject); } if (other.tag == "Win") { winItemEA -= 1; //LobbySceneBtnScript.Instance().myScore += 100; if (Application.loadedLevelName == "Stage_01" && winItemEA == 0) { winPopUp.SetActive(true); // 밑에 보상은 플레이어 오브젝트가 파괴 되지 않아서 실시간으로 오름 //LobbySceneBtnScript.Instance().myScore += 3500; LobbySceneBtnScript.Instance().myGold += 100; LobbySceneBtnScript.Instance().myGem += 35; } if (Application.loadedLevelName == "Stage_02" && winItemEA == 0) { winPopUp.SetActive(true); // 밑에 보상은 플레이어 오브젝트가 파괴 되지 않아서 실시간으로 오름 //LobbySceneBtnScript.Instance().myScore += 3500; LobbySceneBtnScript.Instance().myGold += 100; LobbySceneBtnScript.Instance().myGem += 35; LobbySceneBtnScript.Instance().stage02Clear = true; } if (Application.loadedLevelName == "Stage_03" && winItemEA == 0) { winPopUp.SetActive(true); // 밑에 보상은 플레이어 오브젝트가 파괴 되지 않아서 실시간으로 오름 //LobbySceneBtnScript.Instance().myScore += 3500; LobbySceneBtnScript.Instance().myGold += 100; LobbySceneBtnScript.Instance().myGem += 35; LobbySceneBtnScript.Instance().stage03Clear = true; } if (Application.loadedLevelName == "Stage_04" && winItemEA == 0) { winPopUp.SetActive(true); // 밑에 보상은 플레이어 오브젝트가 파괴 되지 않아서 실시간으로 오름 //LobbySceneBtnScript.Instance().myScore += 3500; LobbySceneBtnScript.Instance().myGold += 100; LobbySceneBtnScript.Instance().myGem += 35; LobbySceneBtnScript.Instance().stage04Clear = true; } } }