При создании префаба я пытаюсь, чтобы каждый отдельный GameObject, составляющий префаб, запускал свои собственные соответствующие скрипты. В принципе,
Я хочу, чтобы префаб сломался после нереста; оставляя отдельные игровые объекты.
У меня GameObjects в Префабе как дети Пустого. Любые предложения.
![enter image description here](https://i.stack.imgur.com/9TcGw.png)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CreateFab : MonoBehaviour
{
public Transform Spawnpoint;
public Rigidbody Prefab;
public void OnClick()
{
Rigidbody RigidPrefab;
RigidPrefab = Instantiate(Prefab, Spawnpoint.position, Spawnpoint.rotation) as Rigidbody;
}
public void DetachFromParent()
{
// Detaches the transform from its parent.
transform.parent = null;
}
}
Cube Script
using UnityEngine;
using UnityEditor;
using System.IO;
public class WallClick : MonoBehaviour
{
string path;
public MeshRenderer mRenderer;
public void OpenExplorer()
{
path = EditorUtility.OpenFilePanel("Overwrite with png", "", "png");
GetImage();
}
void GetImage()
{
if (path != null)
{
UpdateImage();
}
}
void UpdateImage()
{
byte[] imgByte = File.ReadAllBytes(path);
Texture2D texture = new Texture2D(2, 2);
texture.LoadImage(imgByte);
mRenderer.material.mainTexture = texture;
}
}