Skip to content

Commit

Permalink
Powerup time limited
Browse files Browse the repository at this point in the history
  • Loading branch information
rholder613 committed Jun 27, 2020
1 parent d7171e0 commit 58d8eb2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Assets/Scripts/Enemy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class Enemy : MonoBehaviour
{
public float speed = 3f;
public float speed = 2f;
private Rigidbody enemyRb;
private GameObject player;

Expand Down
12 changes: 12 additions & 0 deletions Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class PlayerController : MonoBehaviour
{
public float speed = 5f;
public bool hasPowerup = false;
private float powerUpStrength = 15f;
private Rigidbody playerRb;
private GameObject focalPoint;

Expand All @@ -30,13 +31,24 @@ private void OnTriggerEnter(Collider other)
{
hasPowerup = true;
Destroy(other.gameObject);
StartCoroutine(PowerupCountdownRoutine());
}
}

protected IEnumerator PowerupCountdownRoutine()
{
yield return new WaitForSeconds(7);
hasPowerup = false;
}

private void OnCollisionEnter(Collision collision)
{
if(collision.gameObject.CompareTag("Enemy") && hasPowerup)
{
Rigidbody enemyRigidbody = collision.gameObject.GetComponent<Rigidbody>();
Vector3 awayFromPlayer = collision.gameObject.transform.position - transform.position;

enemyRigidbody.AddForce(awayFromPlayer * powerUpStrength, ForceMode.Impulse);
Debug.Log("Collided with: " + collision.gameObject.name + " with powerup set to " + hasPowerup.ToString());
}
}
Expand Down

0 comments on commit 58d8eb2

Please sign in to comment.