- Home /
Question by
timobugz3 · Jun 01, 2020 at 03:00 PM ·
errorinstantiateexecuteineditmodedonotdestroy
Keep Instantiated GameObject while exit gamemode in unity
Hi,
In the game that I am creating i am trying to keep the wall prefabs that I have instantiated during gamemode even when I switched back to scenemode.
Below is my code. I have attached this code onto my prefab object but it didn't work.
using UnityEngine;
using UnityEditor;
[ExecuteInEditMode]
public class DontDestroy : MonoBehaviour
{
Transform wallInfo;
bool previousState = true;
void Update()
{
wallInfo = gameObject.transform;
if (EditorApplication.isPlaying != previousState)
{
GameObject wallCopy = GameObject.CreatePrimitive(PrimitiveType.Cube);
wallCopy.transform.position = wallInfo.position;
wallCopy.transform.localScale = wallInfo.localScale;
previousState = false;
}
}
}
Thank you in advanced for any help.
Comment
Your answer
Follow this Question
Related Questions
Object reference not set to an instance of an object 1 Answer
Instantiating Rigidbodies on PhotonNetwork? Am I doing it wrong? 1 Answer
updateMassFromShapes error 2 Answers
Instantiating an object as a trigger does not send the trigger event 3 Answers
Could someone help me with instantiate function? It's not working. Weird. 2 Answers