Keeps dropping me an error while trying to read this script and I’m unsure why. Trying to use this as a class


using UnityEngine;
[System.Serializable]
public class PlayerWeapon{
public string weaponName = "Pistol";
public float damage = 10f;
public float range = 100f;
}
@privatas98
Well it seems like you are trying to make a scriptable object. These are very useful when doing exactly what you are doing. This is a video from one of my favorite YouTubers who gives a very good explanation of how to use a scriptable object: Scriptable Object Video
But if you do not wish to do so here is a script which certainly should fit your needs:
using UnityEngine;
//Now when you right click in your project tab and click new you will see your script
//The fileName will be the name of your object if you do not set it
//The menuName will be the name you see when you want to create a new object
[CreateAssetMenu(fileName = "New Weapon", menuName = "Weapon")]
//The ScriptableObject part is very important because it allows you to create this object
public class PlayerWeapon : ScriptableObject
{
//Sets your weapon name
public string weaponName = "Pistol";
//That damage doh.
public float damage = 1000000f;
//What range ;)
public float range = 0.0000001f;
}
using UnityEngine;
[System.Serializable]
public class PlayerWeapon {
public string weaponName = "Pistol";
public float damage = 10f;
public float range = 100f;
}
public class ScriptYouAlreadyHave : MonoBehaviour {
// existing code
}
//
//
You can just add the class to a script you have already written, and it should work.