41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using UnityEngine;
|
|
using VContainer;
|
|
|
|
public class Player : MonoBehaviour
|
|
{
|
|
[SerializeField] private float jumpForce = 1f;
|
|
[SerializeField] private Rigidbody rb;
|
|
[SerializeField] private GameObject splashObject;
|
|
[SerializeField] private Transform splashParent;
|
|
public bool isDead = false;
|
|
public ParticleSystem deadParticle;
|
|
|
|
|
|
[Inject] private IInputReader inputReader;
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
ShowAndHideSplash(collision);
|
|
if (collision.gameObject.CompareTag("Safe") && !isDead)
|
|
{
|
|
rb.linearVelocity = Vector3.up * jumpForce;
|
|
}
|
|
else if(collision.gameObject.CompareTag("Death"))
|
|
{
|
|
isDead = true;
|
|
deadParticle.Play();
|
|
this.GetComponent<Renderer>().enabled = false;
|
|
inputReader.blockedInput = true;
|
|
}
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|