void shooting() { Instantiate(bulletPre, firePoint.position, firePoint.rotation); Instantiate(muzzleFlash, firePoint.position, firePoint.rotation, this.gameObject.transform); StartCoroutine(_cameraShake.shake(.15f, .4f)); shootSound.Play(); }
// Update is called once per frame private void Update() { RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, orientation * transform.right, distance, solidItems); if (hitInfo.collider != null) { if (hitInfo.collider.CompareTag("Enemy")) { hitInfo.collider.GetComponent <bodyPartDmg>().takeDamage(damage); shake.shake(); } destroyProjectile(); } transform.Translate(orientation * transform.right * speed * Time.deltaTime); }
public bool move() { if (!inputGiven) { return(false); } if (Mathf.Abs(destination.x - crate.transform.position.x) > 0.1f) { crate.transform.position = Vector3.MoveTowards(crate.transform.position, new Vector3(destination.x, crate.transform.position.y, destination.z), speed); } else { crate.transform.position = Vector3.MoveTowards(crate.transform.position, new Vector3(crate.transform.position.x, destination.y, destination.z), speed); } if (!cratesound1.isPlaying) { cratesound1.Play(); } StopAllCoroutines(); StartCoroutine(cameraShake.shake(0.05f, 0.1f)); //GameObject dust = Instantiate(Resources.Load("dust")) as GameObject; Debug.Log(destination); if (Vector3.Distance(crate.transform.position, destination) <= 0.1) { inputGiven = false; if (cratesound1.isPlaying) { cratesound1.Stop(); } //StartCoroutine(cameraShake.shake(0.1f, 0.2f)); } return(true); }
void Update() { //player HP controls healthBar.value = health; PlayerPrefs.SetFloat("health", health); if (health <= 0) { Instantiate(deathFX, transform.position, Quaternion.identity); Destroy(gameObject); shake.shake(); } //dynamic health bar colour if (health <= 10) { healthBarFill.color = lowHealthColor; } //player on ground/ double jumps if (isGrounded == true) { jumpTimes = doubleJump; anim.SetBool("isJumping", false); } else { anim.SetBool("isJumping", true); } //if there is more than no jumps, jump if (Input.GetKeyDown(KeyCode.Space) && jumpTimes > 0) { anim.SetTrigger("takeoff"); rb.velocity = Vector2.up * jumpForce; jumpTimes--; Debug.Log(jumpTimes); Debug.Log("is grounded" + isGrounded); } else if (Input.GetKeyDown(KeyCode.Space) && jumpTimes == 0 && isGrounded == true) { anim.SetTrigger("takeoff"); rb.velocity = Vector2.up * jumpForce; } //if dash is not on cd, dash if (timeBtwnDash <= 0) { if (Input.GetKeyDown(KeyCode.LeftShift) && dashTime > 0) { speed = dashSpeed; timeBtwnDash = startTimeBtwnDash; countdown = true; } } else //if cd is active, count down cd { timeBtwnDash -= Time.deltaTime; } // if dash has started, count down from dash duration if (countdown == true) { dashTime -= Time.deltaTime; Debug.Log(dashTime); } //if dash is over, reset speed and dash duration if (dashTime <= 0) { dashTime = startDashTime; speed = originalSpeed; countdown = false; } //resets playerprefs used for testing /*if (Input.GetKeyDown(KeyCode.R)) { * PlayerPrefs.DeleteKey(collectibleType); * collectibleCount = 0; * PlayerPrefs.Save(); * Debug.Log("reset" + PlayerPrefs.GetFloat(collectibleType)); * } * * if (Input.GetKeyDown(KeyCode.T)) { * Debug.Log("checksave" + PlayerPrefs.GetFloat(collectibleType)); * }*/ if (collectibleExists == true) { collectibleCounter.text = PlayerPrefs.GetFloat(collectibleType).ToString() + "/" + maxCollectibles.ToString(); } }