public new void Start() { base.Start(); instance = this; PlayerMovementController = GetComponent <PlayerMovementController>(); PlayerDialogueController = GetComponent <PlayerInteractionController>(); PlayerSettingsController = GetComponent <PlayerSettingsController>(); }
public void StayInScene() { playerInRange = false; exitdialogBox2.SetActive(false); PlayerControllerMain cc = GetComponent <PlayerControllerMain>(); cc.enabled = true; PlaySound(signSound); isGrounded = true; }
//Upon collision with a zombie void OnControllerColliderHit(ControllerColliderHit hit) { if (hit.gameObject.CompareTag("BasicZombie")) { //If the player is not immune (when recently hit) and is alive if (!gameObject.tag.Equals("Immune") && alive) { //Invoke the necessary function HitByZombie(); } } //If the player has hit a player tomb, i,e the dead player if (hit.gameObject.CompareTag("PlayerTomb")) { //Remove the tomb gameobject hit.gameObject.SetActive(false); PlayerDeathController pdc = hit.transform.GetComponentInParent <PlayerDeathController> (); PlayerControllerMain pcm = hit.transform.GetComponentInParent <PlayerControllerMain> (); //If it was player one that was the dead player if (pcm.GetPlayerId() == 1) { GameObject playerOne = GameObject.Find("PlayerOne_Green"); //activate the player's rendering meshes again playerOne.transform.GetChild(2).gameObject.SetActive(true); } //If it was player two that was the dead player, do likewise if (pcm.GetPlayerId() == 2) { GameObject playerTwo = GameObject.Find("PlayerTwo_Blue"); playerTwo.transform.GetChild(2).gameObject.SetActive(true); } //set it to alive pdc.ToggleAlive(); //Has one life pdc.SetLives(1); } }
// Use this for initialization void Start() { Stu = FindObjectOfType <PlayerControllerMain>(); Debug.Log("Poinnter Up"); }
private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag == "ground") { isGrounded = true; Instantiate(dustCloud, jumpPoint.transform.position, dustCloud.transform.rotation); coroutineAllowed = true; } if (collision.gameObject.tag == "MovingPlatform") { gameObject.transform.parent = collision.gameObject.transform; isGrounded = true; } if (collision.gameObject.tag == "RoadBlock") { chatBubble.SetActive(true); PlaySound(chatSound); Invoke("DisableChat", 2.5f); } if (collision.gameObject.tag == "Death") { rb.isKinematic = true; gameObject.GetComponent <Renderer>().enabled = false; animator.SetTrigger("isDead"); dustCloud.SetActive(false); particlesDeath.Play(); PlayerControllerMain cc = GetComponent <PlayerControllerMain>(); cc.enabled = false; health -= 1; PlaySound(hurtClip); StartCoroutine("WaitforDeath"); } if (collision.gameObject.tag == "ExitDoor") { if (key == 1 && key2 == 1 && key3 == 1 && key4 == 1 && key5 == 1) { playerInRange = true; exitdialogBox2.SetActive(true); PlayerControllerMain cc = GetComponent <PlayerControllerMain>(); cc.enabled = false; PlaySound(signSound); rb.velocity = Vector2.zero; isGrounded = false; animator.SetBool("isIdle", true); animator.SetBool("isWalking", false); animator.SetBool("isShifting", false); animator.SetBool("isDashing", false); } else { playerInRange = false; exitdialogBox1.SetActive(true); PlaySound(signSound); } } if (collision.gameObject.tag == "Trampoline") { isGrounded = true; PlaySound(launchClip); rb.velocity = Vector3.up * launchForce; } }
void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "NPC") { isTalking = true; } if (collision.gameObject.tag == "Health") { if (health < 5) { health += 1; Destroy(collision.gameObject); PlaySound(healthClip); } } if (collision.gameObject.tag == "keys") { if (key < 1) { key += 1; PlaySound(crunchClip); Destroy(collision.gameObject); } } if (collision.gameObject.tag == "keys2") { if (key2 < 1) { key2 += 1; PlaySound(crunchClip); Destroy(collision.gameObject); } } if (collision.gameObject.tag == "keys3") { if (key3 < 1) { key3 += 1; PlaySound(crunchClip); Destroy(collision.gameObject); } } if (collision.gameObject.tag == "keys4") { if (key4 < 1) { key4 += 1; PlaySound(crunchClip); Destroy(collision.gameObject); } } if (collision.gameObject.tag == "keys5") { if (key5 < 1) { key5 += 1; PlaySound(crunchClip); Destroy(collision.gameObject); } } if (collision.gameObject.tag == "CheckPoint") { PlaySound(checkPointClip); checkPointFlag.Play(); respawnPoint = checkPoint.transform.position; normalFlag.SetActive(false); touchedFlag.SetActive(true); } if (collision.gameObject.tag == "CheckPoint2") { PlaySound(checkPointClip); checkPointFlag2.Play(); respawnPoint = checkPoint2.transform.position; normalFlag2.SetActive(false); touchedFlag2.SetActive(true); } if (collision.gameObject.tag == "ChatTrigger1") { chatBubble1.SetActive(true); PlaySound(chatSound); Destroy(collision.gameObject); Invoke("DisableChat1", 5f); } if (collision.gameObject.tag == "ChatTrigger2") { chatBubble2.SetActive(true); PlaySound(chatSound); Destroy(collision.gameObject); Invoke("DisableChat2", 5f); } if (collision.gameObject.tag == "ChatTrigger3") { chatBubble3.SetActive(true); PlaySound(chatSound); Destroy(collision.gameObject); Invoke("DisableChat3", 5f); } if (collision.gameObject.tag == "ChatTrigger4") { chatBubble4.SetActive(true); PlaySound(chatSound); Destroy(collision.gameObject); Invoke("DisableChat4", 5f); } if (collision.gameObject.tag == "ChatTrigger5") { chatBubble5.SetActive(true); PlaySound(chatSound); Destroy(collision.gameObject); Invoke("DisableChat5", 5f); } if (collision.gameObject.tag == "ChatTrigger6") { chatBubble6.SetActive(true); PlaySound(chatSound); Destroy(collision.gameObject); Invoke("DisableChat6", 5f); } if (collision.gameObject.tag == "ChatTrigger7") { chatBubble7.SetActive(true); PlaySound(chatSound); Destroy(collision.gameObject); Invoke("DisableChat7", 5f); } if (collision.gameObject.tag == "ChatTrigger8") { chatBubble8.SetActive(true); PlaySound(chatSound); Destroy(collision.gameObject); Invoke("DisableChat8", 6f); } if (collision.gameObject.tag == "Spikes") { rb.isKinematic = true; gameObject.GetComponent <Renderer>().enabled = false; animator.SetTrigger("isDead"); dustCloud.SetActive(false); particlesDeath.Play(); PlayerControllerMain cc = GetComponent <PlayerControllerMain>(); cc.enabled = false; health -= 1; PlaySound(hurtClip); StartCoroutine("WaitforDeath"); } if (collision.gameObject.tag == "PinkSpikes") { rb.isKinematic = true; gameObject.GetComponent <Renderer>().enabled = false; animator.SetTrigger("isDead"); dustCloud.SetActive(false); particlesDeath.Play(); PlayerControllerMain cc = GetComponent <PlayerControllerMain>(); cc.enabled = false; health -= 1; PlaySound(hurtClip); StartCoroutine("WaitforDeath"); } if (collision.gameObject.tag == "Transition") { Transition.SetActive(false); PlayerControllerMain cc = GetComponent <PlayerControllerMain>(); cc.enabled = true; dustCloud.SetActive(true); isDashing = false; } }
void Update() { float movX = Input.GetAxisRaw("Horizontal"); float movY = Input.GetAxisRaw("Vertical"); rb.velocity = new Vector2(movX * Speed, rb.velocity.y); Flip(movX); if (isGrounded == true) { jumpAllowed = true; doubleJumpAllowed = true; JumpIcon.SetActive(true); } if (Input.GetKeyDown(KeyCode.Space) && isGrounded && isTalking == false) { Jump(); } else if (doubleJumpAllowed && Input.GetKeyDown(KeyCode.Space) && isTalking == false) { DoubleJump(); doubleJumpAllowed = false; } if (isGrounded && movX != 0 && coroutineAllowed) { StartCoroutine("SpawnCloud"); coroutineAllowed = false; } if (movX == 0 && isGrounded) { StopCoroutine("SpawnCloud"); coroutineAllowed = true; } if (movX == 0 && isGrounded == true) { animator.SetBool("isIdle", true); } else { animator.SetBool("isIdle", false); } if (movX != 0 && isGrounded == true && Speed == 7) { animator.SetBool("isWalking", true); } else { animator.SetBool("isWalking", false); } if (Speed == 12 && movX != 0 && isGrounded == true) { animator.SetBool("isShifting", true); } else { animator.SetBool("isShifting", false); } if (isDashing == true && movX != 0) { animator.SetBool("isDashing", true); } else { animator.SetBool("isDashing", false); } if (jumpAllowed == true && isGrounded == false && doubleJumpAllowed == true && Input.GetKeyDown(KeyCode.Space)) { animator.SetBool("isJumping", true); } else { animator.SetBool("isJumping", false); } if (doubleJumpAllowed == false && Input.GetKeyDown(KeyCode.Space) && isGrounded == false) { animator.SetBool("isDoubleJumping", true); } else { animator.SetBool("isDoubleJumping", false); } if (Time.time > nextFireTime && isTalking == false) { if (Input.GetMouseButtonDown(1) && movX != 0 && isDashing == false) { isDashing = true; CurrentDashTimer = StartDashTimer; rb.velocity = Vector2.zero; DashDirection = movX; Particles.Play(); audioSource.clip = dashSound; audioSource.Play(); dashIcon.SetActive(false); } if (isDashing) { rb.velocity = transform.right * DashDirection * DashForce; CurrentDashTimer -= Time.deltaTime; cameraInitialPosition = mainCamera.transform.position; InvokeRepeating("StartCameraShaking", 0f, 0.0005f); Invoke("StopCameraShaking", shakeTime); if (CurrentDashTimer <= 0) { isDashing = false; StartCoroutine("Dash"); } } } if (currentStamina > 0.40f && isTalking == false) { isSprinting = true; if (Input.GetKey(KeyCode.LeftShift) && isSprinting == true && movX != 0) { UseStamina(0.40f); Speed = 12f; } else { Speed = 7f; } } else if (currentStamina < 0.40f) { staminaBarShift.value = currentStamina; Speed = 7f; isSprinting = false; } if (key == 1) { keys1.SetActive(true); } else { keys1.SetActive(false); } if (key2 == 1) { keys2.SetActive(true); } else { keys2.SetActive(false); } if (key3 == 1) { keys3.SetActive(true); } else { keys3.SetActive(false); } if (key4 == 1) { keys4.SetActive(true); } else { keys4.SetActive(false); } if (key5 == 1) { keys5.SetActive(true); } else { keys5.SetActive(false); } if (Input.GetKeyDown(KeyCode.R) && isTalking) { if (dialogBox.activeInHierarchy) { dialogBox.SetActive(false); rb.constraints = RigidbodyConstraints2D.None; rb.constraints = RigidbodyConstraints2D.FreezeRotation; isGrounded = true; jumpAllowed = true; } else { dialogBox.SetActive(true); //Make DialogActive rb.constraints = RigidbodyConstraints2D.FreezeAll; //Freeze Movement via Rigidbody2D isGrounded = false; // NoParticles or Animations Active jumpAllowed = false; // No Jump Animation isSprinting = true; } } if (health == 0) { Debug.Log("You Have Died!"); PlayerControllerMain cc = GetComponent <PlayerControllerMain>(); cc.enabled = false; Time.timeScale = 0; backgroundMusic.Pause(); loseMenu.SetActive(true); } if (health == 0) { heart5.SetActive(false); heart4.SetActive(false); heart1.SetActive(false); heart2.SetActive(false); heart3.SetActive(false); } if (health == 1) { heart5.SetActive(false); heart4.SetActive(false); heart3.SetActive(false); heart2.SetActive(false); heart1.SetActive(true); } if (health == 2) { heart5.SetActive(false); heart4.SetActive(false); heart3.SetActive(false); heart2.SetActive(true); heart1.SetActive(true); } if (health == 3) { heart5.SetActive(false); heart4.SetActive(false); heart3.SetActive(true); heart2.SetActive(true); heart1.SetActive(true); } if (health == 4) { heart5.SetActive(false); heart4.SetActive(true); heart3.SetActive(true); heart2.SetActive(true); heart1.SetActive(true); } if (health == 5) { heart5.SetActive(true); heart4.SetActive(true); heart3.SetActive(true); heart2.SetActive(true); heart1.SetActive(true); } }