- Home /
The question is answered, right answer was accepted
PrefabUtility doesn´t work
Hi! This is my first post and my first Unity project. I know a bit of C# but the scripting language in Unity, well, I hope I´m not the only one Googeling like crazy...
Anyhow. I am trying to use the PrefabUtility.xxxxx but everytime I do so, Visual Studio complain that this isnt a valid use of it. I have tried to copy code from here to use in my game that SHOULD work and has for others, but not for me. I just get that angry red line under it, usually with some error like "Does not exsist in the current context.
I have created the Editor-folder and the script as described here: https://docs.unity3d.com/ScriptReference/PrefabUtility.html
What I am after is that I have a ship. When it sinks and hit "DeadZone" I want the script attached to the deadzone to get the original prefab of that ship and spawn it at a spawnobject. It sort of works now but when the ship respawns, it is a clone of the sunken ship with zero hitpoints and a mass like the sun.
I could reset the values with a lot of if-statements but that is not a very elegant solution and I have time to tinker just to get to that... I have tried the forum and Google but they all refer to this PrefabUtility...
Really hard to know what's going on without seeing your code
Did you miss namespace like "using UnityEditor;" on top of your script?
Typical N00b mistake. That, of course, solved the problem. Thank you sir!
Follow this Question
Related Questions
Counting prefabs in screen?,Problem with counting prefabs in screen 1 Answer
Problem with player prefab 2 Answers
creating and using list of prefabs 2 Answers
Running scripts from editor 1 Answer