77 lines
2.2 KiB
C#
77 lines
2.2 KiB
C#
using Invector.vMelee;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Beyond
|
|
|
|
{
|
|
public class ShieldCollisionController : MonoBehaviour
|
|
{
|
|
[SerializeField] private GameObject shieldCollisionEffect;
|
|
|
|
private List<Collider> colliders = new List<Collider>();
|
|
|
|
public Collider shieldCollider;
|
|
|
|
private void OnCollisionEnter(Collision collision)
|
|
{
|
|
Debug.Log(collision.collider);
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (!(other.gameObject.CompareTag("Weapon")))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!other.GetComponent<vHitBox>())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (colliders.Contains(other))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Vector3.Distance(other.transform.position, shieldCollider.transform.position) < 0.7f)
|
|
{
|
|
return;
|
|
}
|
|
|
|
colliders.Add(other);
|
|
StartCoroutine(RemoveColliderFromListCoroutine(other));
|
|
|
|
var collisionPoint = other.ClosestPoint(transform.position);
|
|
var collisionNormal = transform.position - collisionPoint;
|
|
|
|
Vector3 dir = (other.transform.position - this.transform.position);
|
|
|
|
LayerMask mask = LayerMask.GetMask("Player");
|
|
RaycastHit hit;
|
|
Physics.Raycast(other.transform.position + dir, -dir, out hit, 300f, mask);
|
|
Debug.DrawRay(hit.point, hit.normal, Color.red, 5, false);
|
|
Debug.Log(hit.collider.gameObject.layer);
|
|
GameObject hitEffect = Instantiate(shieldCollisionEffect, hit.point, Quaternion.LookRotation(hit.normal), transform);
|
|
float dist = Vector3.Distance(hitEffect.transform.position, shieldCollider.ClosestPoint(hitEffect.transform.position));
|
|
Destroy(hitEffect, 2f);
|
|
}
|
|
|
|
public void EnableCollisions()
|
|
{
|
|
}
|
|
|
|
private IEnumerator RemoveColliderFromListCoroutine(Collider collider)
|
|
{
|
|
yield return new WaitForSeconds(1f);
|
|
colliders.Remove(collider);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
colliders.Clear();
|
|
}
|
|
}
|
|
} |