// Update is called once per frame
void Update()
{
+ if (isGrounded == true && Input.GetButtonDown("Jump"))
+ {
+ isJumping = true;
+ jumpTimeCounter = jumptime;
+ rb.velocity = new Vector2(rb.velocity.x, jumpForce);
+ }
+
+ if (Input.GetButton("Jump") && isJumping == true)
+ {
+ if (jumpTimeCounter > 0)
+ {
+ rb.velocity = new Vector2(rb.velocity.x, jumpForce);
+ jumpTimeCounter -= Time.deltaTime;
+ FindObjectOfType<AudioManager>().Play("sprung");
+ }
+ }
+
if (Input.GetButtonUp("Jump"))
{
isJumping = false;
if (powerUps.mouseIsGardener == true)
{
- if (Input.GetButtonDown("Fire1"))
+ if (Input.GetButtonDown("Fire1") && ! isShooting)
{
- if (isShooting) return;
-
isShooting = true;
GameObject b = Instantiate(bullet);
- b.GetComponent<Scissors>().StartShoot(isFacingLeft);
+ b.GetComponent<Scissors>().StartShoot(isFacingLeft, rb.velocity);
b.transform.position = bulletSpawnPos.transform.position;
Invoke("ResetShoot", shootDelay);
if (oldSign == -Math.Sign(rb.velocity.x))
rb.velocity = new Vector2(0, rb.velocity.y);
}
-
- if (isGrounded == true && Input.GetButtonDown("Jump"))
- {
- isJumping = true;
- jumpTimeCounter = jumptime;
- rb.velocity = new Vector2(rb.velocity.x, jumpForce);
- }
-
- if (Input.GetButton("Jump") && isJumping == true)
- {
- if (jumpTimeCounter > 0)
- {
- rb.velocity = new Vector2(rb.velocity.x, jumpForce);
- jumpTimeCounter -= Time.fixedDeltaTime;
- FindObjectOfType<AudioManager>().Play("sprung");
- }
- }
}
void ResetShoot()
+using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[SerializeField]
float lifeTime = 10;
- public void StartShoot(bool isFacingLeft)
+ public void StartShoot(bool isFacingLeft, Vector2 velocity)
{
Rigidbody2D rb2d = GetComponent<Rigidbody2D>();
- if(isFacingLeft == true)
+ transform.localScale = new Vector3(0.4f, 0.4f, 1);
+
+ if (isFacingLeft == true)
{
- rb2d.velocity = new Vector2(-speed, 0);
- transform.localScale = new Vector3(-0.4f, 0.4f, 1);
+ rb2d.velocity = new Vector2(-speed, 0) + velocity;
}
else
{
- rb2d.velocity = new Vector2(speed, 0);
- transform.localScale = new Vector3(0.4f, 0.4f, 1);
+ rb2d.velocity = new Vector2(speed, 0) + velocity;
}
+ Vector2 movementDirection = rb2d.velocity;
+ movementDirection.Normalize();
+ transform.rotation = Quaternion.LookRotation(Vector3.forward, movementDirection) * Quaternion.Euler(0, 0, 90);
+
Destroy(gameObject, lifeTime);
}
}