30 lines
757 B
C#
30 lines
757 B
C#
using UnityEngine;
|
|
|
|
public class BreakFruit : MonoBehaviour
|
|
{
|
|
public Transform parts;
|
|
|
|
private Transform breakable;
|
|
|
|
public void Run()
|
|
{
|
|
if ((bool)breakable)
|
|
{
|
|
return;
|
|
}
|
|
breakable = Object.Instantiate(parts, base.transform.position, base.transform.rotation);
|
|
breakable.localScale = base.transform.localScale;
|
|
if ((bool)breakable.GetComponent<AudioSource>())
|
|
{
|
|
breakable.GetComponent<AudioSource>().pitch = Random.Range(0.84f, 1.28f);
|
|
}
|
|
foreach (Transform item in breakable)
|
|
{
|
|
item.GetComponent<Rigidbody>().AddExplosionForce(200f, base.transform.position, 3f, 0.05f);
|
|
Object.Destroy(t: Random.Range(5f, 30f), obj: item.gameObject);
|
|
}
|
|
Object.Destroy(breakable.gameObject, 30f);
|
|
Object.Destroy(base.gameObject);
|
|
}
|
|
}
|