30 lines
785 B
C#
30 lines
785 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class DebrisPiece : MonoBehaviour
|
|
{
|
|
private Rigidbody _rb;
|
|
|
|
private void Awake()
|
|
{
|
|
_rb = GetComponent<Rigidbody>();
|
|
if (_rb == null)
|
|
_rb = gameObject.AddComponent<Rigidbody>();
|
|
}
|
|
|
|
public void Launch(Vector3 explosionPos, float force, Material material)
|
|
{
|
|
if (material != null)
|
|
{
|
|
MeshRenderer mr = GetComponent<MeshRenderer>();
|
|
if (mr != null) mr.sharedMaterial = material;
|
|
}
|
|
|
|
_rb.AddExplosionForce(force, explosionPos, 20f, 3f, ForceMode.Impulse);
|
|
_rb.AddTorque(Random.insideUnitSphere * force * 0.8f, ForceMode.Impulse);
|
|
|
|
Destroy(gameObject, Random.Range(3f, 7f));
|
|
}
|
|
}
|