58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using UnityEngine;
|
|
using VContainer;
|
|
|
|
public class Player : MonoBehaviour, IPlayer
|
|
{
|
|
[SerializeField] private float jumpForce = 3f;
|
|
[SerializeField] private Rigidbody rb;
|
|
[SerializeField] private GameObject splashObject;
|
|
[SerializeField] private Transform splashParent;
|
|
[SerializeField] private ParticleSystem deadParticle;
|
|
[SerializeField] private ParticleSystem jumpParticle;
|
|
|
|
public bool isDead { get; private set; }
|
|
|
|
|
|
[Inject] private IInputReader inputReader;
|
|
[Inject] private DeathScreenController deathScreenController;
|
|
|
|
private void Start()
|
|
{
|
|
isDead = false;
|
|
}
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
ShowAndHideSplash(collision);
|
|
if(isDead) return;
|
|
|
|
if (collision.gameObject.CompareTag("Safe"))
|
|
{
|
|
rb.linearVelocity = Vector3.up * jumpForce;
|
|
jumpParticle.Play();
|
|
}
|
|
else if(collision.gameObject.CompareTag("Death"))
|
|
{
|
|
isDead = true;
|
|
deadParticle.Play();
|
|
this.GetComponent<Renderer>().enabled = false;
|
|
inputReader.blockedInput = true;
|
|
deathScreenController.ShowDeathScreen();
|
|
}
|
|
}
|
|
|
|
private void ShowAndHideSplash(Collision collision)
|
|
{
|
|
float splashYPos = collision.transform.position.y + 0.155f;
|
|
ContactPoint contact = collision.contacts[0];
|
|
Vector3 surfacePoint = new Vector3(contact.point.x, splashYPos, contact.point.z);
|
|
GameObject instancedSplash = Instantiate(splashObject, surfacePoint, splashObject.transform.rotation, splashParent);
|
|
Destroy(instancedSplash, 2f);
|
|
}
|
|
}
|
|
|
|
public interface IPlayer
|
|
{
|
|
bool isDead { get; }
|
|
}
|