Adding a Script onto another Script

I am working on RPG style combat. I created various classes (scripts) for Characters, Weapons, etc. Im having a problem adding a Weapon onto my Character. For example I have a Character that wants to be able to use a Sword.
Here is my Weapons script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class Weapon : MonoBehaviour
{
    public string weaponName;
    public string description;

    public int baseDamage;

    public bool isRanged;

    // Can this weapon damage a whole party; i.e, bomb
    public bool wholeParty;

    public int speedModifier;
    public int minWeaponSkill;

    public Weapon CreateWeapon(string weaponName, string description, int baseDamage,
        bool isRanged, bool wholeParty, int speedModifier, int minWeaponSkill)
    {
        // Setup weapon properties
        this.weaponName = weaponName;
        this.description = description;
        this.baseDamage = baseDamage;
        this.isRanged = isRanged;
        this.wholeParty = wholeParty;
        this.speedModifier = speedModifier;
        this.minWeaponSkill = minWeaponSkill;

        return this;
    }

And here is my Character script:

using System;
using UnityEngine;

[System.Serializable]
public class Character : MonoBehaviour
{

    //public GameObject prefab;

    public Weapon currentWeapon;

… And so forth . I am able to Instantiate a Character GameObject. What would be the procedure to properly create a new “Sword”, and assign it to a given Characters currentWeapon slot. Im attempting to do this inside another class called CombatHandler. Just looking for a general procedure that would accomplish this .
Ive attempted a few ways and I get various errors such as a “null reference exception”
I’m a rookie here, so any help that can be provided would be appreciated. Thank you.

Since weapon is a MonoBehaviour, you could normally just use AddComponent() to add a weapon component to the same GameObject your character script is on and then assign that component to currentWeapon.

However, it’s possible you might just use a scriptableObject or even just a class that holds some data you pull from a text file.

Interesting OOP development. It seems to me that you come from C++ or another low level language. If I am wrong, it means that you understand the OOP main idea. You need a reference and it rolls. Take a look at the next example which is easier than yours. At first Object class and another one for reference. On your player there is only the second script - no more ++

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class Weapon // nothing more here
{
    public string weaponName;
    public int damage;
    public int cost;

    public Weapon CreateWeapon(string weaponName, int damage, int cost)
    {
        this.weaponName = weaponName;
        this.damage = damage;
        this.cost = cost;

        return this;
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    public Weapon newWeapon;

    void Start()
    {
        newWeapon.CreateWeapon("knife", 10, 20);  
        Debug.Log(newWeapon.weaponName + " " + newWeapon.damage + " " + newWeapon.cost);
    }

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {   // or you can create another object
            newWeapon.CreateWeapon("saber", 20, 30);
            Debug.Log(newWeapon.weaponName + " " + newWeapon.damage + " " + newWeapon.cost);
        }
    }
}

Thank you all so far for your replies, I’ll consider these options. I started with C++ 20+ years ago in H.S., getting back into programming for enjoyment. For more clarity, I’ll include a section of my CombatHandler, so you can get a sense of what I’m trying to prototype:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[System.Serializable]
public class CombatHandler : MonoBehaviour
{


    public GameObject pfCharacter;
    public List<GameObject> Characters = new List<GameObject>();


    // Start is called before the first frame update
    void Start()
    {
     
        SetupCombat();
    }

    // Update is called once per frame
    void Update()
    {
        // This  Attack() method works. No equipped weapon, just a base damage plus a random number.
        int damage;
        damage = Characters[0].GetComponent<Character>().Attack();

// *** This is what I was trying to do, and it returns an error
      // Weapon sword = sword.CreateWeapon("Long Sword", "A mighty sword", 10, false, false, 0, 0);
      //  Characters[0].GetComponent<Character>().currentWeapon = sword;

    }

    void SetupCombat(CombatMode combatMode)
    {
 
        SpawnCharacter();
    }

    private void SpawnCharacter()
    {
       

        //TODO: Iterate though party, spawn each character

        //Instanaiate a new character
        GameObject character = Instantiate(pfCharacter, new Vector3(1, 0, 4), this.transform.rotation) as GameObject;
        character.GetComponent<Character>().Create("Aaragorn", CharacterClass.Knight);
        character.name = "Aragorn";
        Characters.Add(character);

    // This isn't working 
    Weapon sword;
        character.GetComponent<Character>().currentWeapon = sword.CreateWeapon("Sword", "A mighty longsword", 5, false, false, 1, 0);
    }

    private void EndCombat()
    {
        // Cleanup after combat has ended
    }
}
        private void SpawnCharacter()
        {
            //TODO: Iterate though party, spawn each character

            //Instanaiate a new character
            GameObject character = Instantiate(pfCharacter, new Vector3(1, 0, 4), this.transform.rotation) as GameObject;
            character.GetComponent<Character>().Create("Aaragorn", CharacterClass.Knight);
            character.name = "Aragorn";
            Characters.Add(character);

            // This isn't working
            var characterWeapon = character.GetComponent<Character>().currentWeapon;
            characterWeapon = new Weapon("sword","best weapon in the world");

            Debug.Log(characterWeapon.name);
        }
    }
    public class Weapon
    {
    public string name;
    public string desc;
        public Weapon(string name,string desc)
        {
            this.name = name;
            this.desc = desc;
        }
    }

I think your code on line 53 and 54 doesnt make sense you create some variable weapon on 53 and then create new variable Weapon as return of your method on line 54, i edited my post above , you can have List of playeritem on player now

Thank you, I’m def going to try this out

Thank you all for the advice; I implemented the following way, and called and Attack method that worked!

GameObject character = Instantiate(pfCharacter, new Vector3(1, 0, 4), this.transform.rotation) as GameObject;
        character.GetComponent<Character>().Create("Aaragorn", CharacterClass.Knight);
        character.name = "Aragorn";
     

        var characterWeapon = character.GetComponent<Character>().currentWeapon;
       
       characterWeapon.CreateWeapon("Sword", "A mighty longsword", 1, false, false, 1, 0);