50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using UnityEngine;
|
|
using VContainer;
|
|
|
|
public class Player : MonoBehaviour, IPlayer
|
|
{
|
|
public float jumpforce = 4f;
|
|
public Rigidbody BallRb;
|
|
public bool isDead { get; private set; }
|
|
|
|
[Inject] ScoreService scoreService;
|
|
[Inject] InputReader inputReader;
|
|
[Inject] DeathScreenController deathScreenController;
|
|
|
|
void Start()
|
|
{
|
|
if (BallRb == null)
|
|
{
|
|
BallRb = GetComponent<Rigidbody>();
|
|
}
|
|
}
|
|
|
|
void OnCollisionEnter(Collision collision)
|
|
{
|
|
if (collision.collider.CompareTag("Platform") && !isDead)
|
|
{
|
|
BallRb.linearVelocity = new Vector3(0, jumpforce, 0);
|
|
}
|
|
else if (collision.collider.CompareTag("Death"))
|
|
{
|
|
Die();
|
|
}
|
|
}
|
|
|
|
void Die()
|
|
{
|
|
Debug.Log("Player is Dead");
|
|
isDead = true;
|
|
deathScreenController.ShowDeathScreen(scoreService.score,scoreService.GetHighscore());
|
|
}
|
|
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if(other.CompareTag("ScoreTrigger"))
|
|
{
|
|
scoreService.AddScore();
|
|
}
|
|
}
|
|
}
|