i want to create a script that allows me to make new weapons without writing new scripts. i created a script that has walues on it. all are “static” and “public”.
so can anyone help me?
i tried scriptable object but i couldnt pull it off.
Script-able objects are def the way to go. You should give it another go. Here’s a sample for you. Create a new C# script, call it Weapon.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Weapons/Weapon")]
public class Weapon : ScriptableObject
{
// You can add any values you want to here, these below are just examples
public float fireRate;
public int weaponDamage;
public int clipSizeAmmo;
public int maxCarryAmmo;
public float reloadTime;
public float equipTime;
public float unequipTime;
}
//compile the script above and create a new script called WeaponReference. Below is the WeaponReference script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
//This script should be on each individual weapon
public class WeaponReference : MonoBehaviour
{
public Weapon weaponStats;//This is the reference to your weapon scriptable object , now you can access the values and change for each weapon. You must first create a new weapon before your able to assign the weapon to this.
}
//if this helped you please mark answer as answered! Thanks =]