2019-08-04 00:48:41 +02:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Saltosion.OneWeapon {
|
|
|
|
|
public class Explodable : MonoBehaviour {
|
|
|
|
|
public GameObject[] BodypartPrefabs;
|
|
|
|
|
public bool DebugExplode = false;
|
|
|
|
|
|
|
|
|
|
private void Start() {
|
|
|
|
|
foreach (GameObject Obj in BodypartPrefabs) {
|
|
|
|
|
Rigidbody2D Body = Obj.GetComponent<Rigidbody2D>();
|
|
|
|
|
if (Body == null) {
|
|
|
|
|
Debug.LogError($"'{Obj.name}' is an explodable bodypart, and does not have a Rigidbody2D!\n\n" +
|
|
|
|
|
"Therefore it cannot be exploded. Please provide one.\n" +
|
|
|
|
|
"Following is the GameObject that needs to get a Rigidbody2D.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update() {
|
|
|
|
|
if (DebugExplode) {
|
|
|
|
|
DebugExplode = false;
|
2019-08-04 02:00:18 +02:00
|
|
|
|
Explode(false);
|
2019-08-04 00:48:41 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-04 02:00:18 +02:00
|
|
|
|
public void Explode(bool destroyGameObject) {
|
2019-08-04 00:48:41 +02:00
|
|
|
|
foreach (GameObject Obj in BodypartPrefabs) {
|
2019-08-04 01:45:32 +02:00
|
|
|
|
// No body parts flying in censored mode
|
2019-08-04 18:57:06 +02:00
|
|
|
|
float DirectionRadians = Random.value * Mathf.PI * 2.0f;
|
|
|
|
|
Vector2 Direction = new Vector2(Mathf.Cos(DirectionRadians), Mathf.Sin(DirectionRadians));
|
2019-08-04 01:45:32 +02:00
|
|
|
|
if (!Options.CensorGore) {
|
|
|
|
|
GameObject NewObj = Instantiate(Obj, transform.position, new Quaternion(), null);
|
|
|
|
|
Rigidbody2D Bodypart = NewObj.GetComponent<Rigidbody2D>();
|
|
|
|
|
if (Bodypart == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
float Force = 0.5f + Random.value * 0.5f;
|
2019-08-04 18:57:06 +02:00
|
|
|
|
Bodypart.AddForce(Direction * Force, ForceMode2D.Impulse);
|
2019-08-04 01:45:32 +02:00
|
|
|
|
Bodypart.AddTorque((Random.value - 0.5f) * Force, ForceMode2D.Impulse);
|
2019-08-04 00:48:41 +02:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-04 01:45:32 +02:00
|
|
|
|
// Blood is replaced by flowers though, no problem with that
|
2019-08-04 19:04:08 +02:00
|
|
|
|
BloodLauncher.Splatter(transform.position + (Vector3)Direction * 0.5f, Vector2.zero, 70, 50f, 360f);
|
2019-08-04 00:48:41 +02:00
|
|
|
|
}
|
2019-08-04 02:00:18 +02:00
|
|
|
|
|
|
|
|
|
if (destroyGameObject) {
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
2019-08-04 00:48:41 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|