initial commit
This commit is contained in:
29
Assets/Scripts/Rocket/DebrisPiece.cs
Normal file
29
Assets/Scripts/Rocket/DebrisPiece.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user