Hey everyone, hoping for some help on using a function to calculate exp using an array.
I have these two scripts:
using System.Collections;
using System.Collections.Generic;
using UnityEditor.Experimental;
using UnityEngine;
[CreateAssetMenu(fileName = "New Job", menuName = "ScriptableObjects/Job")]
public class CharacterJobs_SO : ScriptableObject
{
public new string name = "Job Name";
public int currentLevel = 1;
public int maxLevel = 99;
private int currentExp = 0;
public int[] expNext;
public float growthRate;
public int baseExp;
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TestJobCall : MonoBehaviour
{
public CharacterJobs_SO job;
// Start is called before the first frame update
void Awake()
{
job.expNext = new int[job.maxLevel];
job.expNext[1] = job.baseExp;
for (int i = 2; i < job.expNext.Length; i++)
{
job.expNext[i] = Mathf.FloorToInt(job.expNext[i - 1] * 1.3f);
}
Debug.Log("My class is " + job.name + " and my growth modifier to level up is " + job.growthRate + ", which means to reach level 3 I need " + job.expNext[3] + ".");
}
}
One is the ScriptableObject that holds information for a job, and the ability to add in a growthRate for the exp needed for each level, which the test script then calculates and creates values for on start (at least that’s the idea).
However, when I run the function in the test script, the answer keeps coming up 0. Can anyone explain where I’ve gone wrong?