When spawning a Prefab, I'm trying to have each individual GameObject that makes up the Prefab run its own respective scripts. Basically, I want the Prefab to break after spawning; leaving individual game Objects.
I have the GameObjects in the Prefab as children of an Empty. Any suggestions.
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;
}
}