Initial commit
This commit is contained in:
40
Assets/Scripts/PlayerScripts/Player.cs
Normal file
40
Assets/Scripts/PlayerScripts/Player.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
2
Assets/Scripts/PlayerScripts/Player.cs.meta
Normal file
2
Assets/Scripts/PlayerScripts/Player.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 614bffbd597c49349a47f76b0ba8b277
|
||||
Reference in New Issue
Block a user