I’m following a tutorial on creating spells and have the player play them. Far as I can see there is no issues with the script but can not create a spell.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class SpellCreator : EditorWindow
{
[MenuItem("Spell Maker/Spell Wizard")]
static void Init()
{
SpellCreator spellWindow = (SpellCreator)CreateInstance(typeof(SpellCreator));
spellWindow.Show();
}
Spell tempSpell = null;
SpellManager spellManager = null;
void OnGUI()
{
if (spellManager = null)
{
spellManager = GameObject.Find("SpellManager").GetComponent<SpellManager>();
}
if (tempSpell)
{
tempSpell.spellName = EditorGUILayout.TextField("Spell Name", tempSpell.spellName);
tempSpell.spellPrefab = (GameObject)EditorGUILayout.ObjectField("Spell Prefab", tempSpell.spellPrefab, typeof(GameObject), false);
tempSpell.spellCollisionParticle = (GameObject)EditorGUILayout.ObjectField("Spell Collision Effect", tempSpell.spellCollisionParticle, typeof(GameObject), false);
tempSpell.spellIcon = (Texture2D)EditorGUILayout.ObjectField("Spell Icon", tempSpell.spellIcon, typeof(Texture2D), false);
tempSpell.spellManaCost = EditorGUILayout.IntField("Mana Cost", tempSpell.spellManaCost);
tempSpell.spellMaxDamage = EditorGUILayout.IntField("Maxium Damage", tempSpell.spellMaxDamage);
tempSpell.projectileSpeed = EditorGUILayout.IntField("Projectile Speed", tempSpell.projectileSpeed);
EditorGUILayout.Space();
if (tempSpell == null)
{
if (GUILayout.Button("Create Spell"))
{
tempSpell = CreateInstance<Spell>();
}
}
else
{
if (GUILayout.Button("Create Scriptable Object"))
{
AssetDatabase.CreateAsset(tempSpell, "Assets/Resources/Spells/" + tempSpell.spellName + ".asset");
AssetDatabase.SaveAssets();
spellManager.spellList.Add(tempSpell);
Selection.activeObject = tempSpell;
tempSpell = null;
}
if (GUILayout.Button("Reset"))
{
Reset();
}
}
}
void Reset()
{
if (tempSpell)
{
tempSpell.spellName = "";
tempSpell.spellIcon = null;
tempSpell.spellManaCost = 0;
tempSpell.spellMaxDamage = 0;
tempSpell.spellMinDamage = 0;
tempSpell.spellPrefab = null;
tempSpell.spellCollisionParticle = null;
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spell : ScriptableObject
{
public string spellName = "";
public GameObject spellPrefab = null;
public GameObject spellCollisionParticle = null;
public Texture2D spellIcon = null;
public int spellManaCost = 0;
public int spellMinDamage = 0;
public int spellMaxDamage = 0;
public int projectileSpeed = 0;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SpellManager : MonoBehaviour
{
public List<Spell> spellList = new List<Spell>();
}
You placed the Reset method inside of the OnGUI method. It should be outside of it.
When your code has a syntax error, it will not recompile. Make sure to check the console to see if you have any errors.

