Skip to content

Instantly share code, notes, and snippets.

@MisterKidX
Last active August 11, 2024 13:18
Show Gist options
  • Save MisterKidX/ca00fa39a698cabbe93974296aa6b1bc to your computer and use it in GitHub Desktop.
Save MisterKidX/ca00fa39a698cabbe93974296aa6b1bc to your computer and use it in GitHub Desktop.
A gameobject that behaves differently whether it is a prefab or a runtime object.
using UnityEngine;
public class SelfCreatingPrefab : MonoBehaviour
{
private int fieldA;
private int fieldB;
public SelfCreatingPrefab Init(int arg1, int arg2)
{
if (!gameObject.scene.IsValid())
{
var runtime = Instantiate(this);
return runtime.Init(arg1, arg2);
}
fieldA = arg1;
fieldB = arg2;
return this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment