Last active
August 11, 2024 13:18
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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