A little stuck with passing a function - getting an error - C#

So I have a random number generator script and i’m trying to access one of its functions from another game object with a script attached to it.

The object that has my RNG.cs attached to it is called Roller. Here is the RNG.cs

using UnityEngine;
using System.Collections;

public class RNG : MonoBehaviour {

    private int rngD4 = 4;
    private int rngD6 = 6;
    private int rngD8 = 8;
    private int rngD10 = 10;
    private int rngD12 = 12;
    private int rngD20 = 20;
    private int rngD100 = 100;

    private int theRoll;

    public void D4(){
        int theRoll = Random.Range(1, rngD4);
    }
    public void D6(){
        int theRoll = Random.Range(1, rngD6);
    }
    public void D8(){
        int theRoll = Random.Range(1, rngD8);
    }
    public void D10(){
        int theRoll = Random.Range(1, rngD10);
    }
    public void D12(){
        int theRoll = Random.Range(1, rngD12);
    }
    public void D20(){
        int theRoll = Random.Range(1, rngD20);
    }
    public void D100(){
        int theRoll = Random.Range(1, rngD100);
    }
}

What I’m having a problem with is how to simply pass ->theRoll<- (which should be the number generated) to WeaponDamage in my script attached to the weapon.

using UnityEngine;
using System.Collections;

public class LongSword : MonoBehaviour {

    public GameObject Roller;
    private string WeaponName = "Long Sword";
    public int WeaponDelay = 3;
    public int WeaponRange = 3;

    public static int WeaponDamage;

    void Start()
    {
        WeaponDamage = Roller.GetComponent<RNG>().D8;    //rolling of the specific damage dice from RNG.cs
    }
}

The specific error I’m getting is:
Cannot convert method group D8' to non-delegate type int’. Consider using parentheses to invoke the method

I THINK I’m aware of what the problem is, but I’m having a hard time getting my head around it. The other thing I’m concerned with - is when I invoke my function “Attack” in another script, that it will pass the same int over and over again, as opposed to getting a new roll every time. (Maybe not - but its a concern)

The attack function (I’ve not passed the variable yet to the script (its currently -10)

private void Attack(){

        float distance = Vector3.Distance (target.transform.position, transform.position);

        Vector3 dir = (target.transform.position - transform.position).normalized;
        float direction = Vector3.Dot (dir, transform.forward);

        Debug.Log(direction);

        if (distance < 2.5f) {
            if(direction > 0) {
                EnemyHealth eh = (EnemyHealth)target.GetComponent ("EnemyHealth");
                eh.AdjustCurrentHealth (-10);
            }

Can anyone give me a hand with this? I’d certainly appreciate it. Getting a handle on this would certainly help me in many respects, considering I’m going to be working an init roll, delay and range into my attack script as well.

Problem 1: I guess there’s an error message?
Problem 2: I don’t get it. What variable do you pass usually instead of -10?

You need to give your Roll methods a return type. You can read about that here https://msdn.microsoft.com/en-us/library/ms173114.aspx

    using UnityEngine;
    using System.Collections;
   
    public class RNG : MonoBehaviour {
   
        private int rngD4 = 4;
        private int rngD6 = 6;
        private int rngD8 = 8;
        private int rngD10 = 10;
        private int rngD12 = 12;
        private int rngD20 = 20;
        private int rngD100 = 100;
   
        private int theRoll;
   
        public int D4(){
            return Random.Range(0, rngD4);
        }
        public int D6(){
            return Random.Range(0, rngD6);
        }
        public int D8(){
            return Random.Range(0, rngD8);
        }
        public int D10(){
            return Random.Range(0, rngD10);
        }
        public int D12(){
            return Random.Range(0, rngD12);
        }
        public int D20(){
            return Random.Range(0, rngD20);
        }
        public int D100(){
            return Random.Range(0, rngD100);
        }
    }

When accessing the method you need to use () at the end of the call like this :

WeaponDamage = Roller.GetComponent<RNG>().D8();

One more thing… Random.Range will never return the max value you pass it. So for example your D100 method will be a 1/99 chance instead of a 1/100 chance. Keep this in mind when using the Random class.

Hope this helps.

The error message (consider using parentheses to invoke the method) is pretty specific:

Roller.GetComponent<RNG>().D8;

You’re missing () after D8.

Another issue though: Random.Range()'s int overload is inclusive-exclusive, which means you will never get the second value, only second value - 1. You need to adjust all your numbers accordingly because you’ll never see a 4, 6, 8, 10, 12, 20 or 100 number result.

And finally, why are you making this a MonoBehaviour at all? It seems like you could just make a class with a bunch of static functions.

This! Thank you so much! For others talking about the parenthesis, I did use them to invoke - but I was still receiving the error as I was not returning the value in the RNG.cs dice rolls. Thanks everyone for your help.