Initial commit
This commit is contained in:
42
Assets/Materials/Scripts/WallHitParticles.cs
Normal file
42
Assets/Materials/Scripts/WallHitParticles.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class WallHitParticles : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private GameObject hitParticlesPrefab;
|
||||
[SerializeField] private float minHitSpeed = 2f;
|
||||
[SerializeField] private float destroyDelay = 2f;
|
||||
|
||||
private Rigidbody _rb;
|
||||
private bool _hasHit = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_rb = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
if (_hasHit)
|
||||
return;
|
||||
|
||||
if (collision.gameObject.CompareTag("Wall") == false)
|
||||
return;
|
||||
|
||||
if (_rb.velocity.magnitude < minHitSpeed)
|
||||
return;
|
||||
|
||||
_hasHit = true;
|
||||
|
||||
Vector3 hitPoint = collision.contacts[0].point;
|
||||
Quaternion hitRotation =
|
||||
Quaternion.LookRotation(collision.contacts[0].normal);
|
||||
|
||||
GameObject particles =
|
||||
Instantiate(hitParticlesPrefab, hitPoint, hitRotation);
|
||||
|
||||
Destroy(particles, destroyDelay);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user