| 12345678910111213141516171819202122232425262728 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PostSplitBehaviour : MonoBehaviour
- {
- public Material PostSplitMat;
- public Vector3 ExplosionPosition;
- public void PostSplit(GameObject[] newGOs)
- {
- foreach (GameObject go in newGOs)
- {
- MeshRenderer renderer = go.GetComponent<MeshRenderer>();
- if (PostSplitMat != null)
- {
- for (int i = 0; i < renderer.materials.Length; i++)
- {
- renderer.materials[i] = PostSplitMat;
- }
- }
- go.transform.position = gameObject.transform.position + go.transform.position;
- go.transform.rotation = gameObject.transform.rotation;
- Rigidbody rb = go.GetComponent<Rigidbody>();
- rb.AddForceAtPosition(Random.rotation * Vector3.forward * Random.Range(2f, 4f), gameObject.transform.position, ForceMode.Impulse);
- }
- }
- }
|