Adding Job To Job Tree

I’m trying to figure out how i would add one of the Jobs below in the image to the top and for it to display the health of the job selected.

I have this code at the moment nothing much really on it as I’m not sure where to start. :confused: any Advice would be good!

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class gamebitSystem : MonoBehaviour {
    public Text currentJobHealth;
    public GameObject currentJobSlot;



    // Use this for initialization
    void Start () {

    }
   
    // Update is called once per frame
    void Update () {
        currentJobHealth.text = "This will Display The Current Job Health";
    }
}

first off classes are generally Capital first letter :stuck_out_tongue:

What is your hierarchy setup in that picture? are the job buttons part of the same canvas or something separate?

Really? most Tutorials on Youtube don’t capitalize the first letter haha I’ll keep that in mind now :slight_smile:
and it’s a canvas with two panels Panel 1 has image-text and panel 2 has the three images. :slight_smile:
Ive been thinking about how it could be done and would it be the same way an inventory is done?

Classes make Objects… GameObject, Transform, MeshRenderer etc. all classes.

When you make an instance of an object it’s customary to store it as a variable, which are usually lowercase first letter. There could be gameObject, transform, meshRenderer, myTransform or whatever you like.

GameObject go = Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;

go and prefab are likely variables in this script, zero and identity are static variables (don’t need an instance to access them) of the classes Vector3 and Quaternion respectively. GameObject, Vector3 and Quaternion are classes.

Customary, not mandatory, but sticking with custom helps others understand the code easily… and having said that if you tried to use a class within the UnityEngine with the wrong capitalisation you’ll get errors, i.e.

gameObject go = ....

is wrong.

Unity used to allow component references like “transform” and “rigidbody” without explicitly declaring them (it did that behind the scenes)… this has been (or is being, not entirely sure) phased out in Unity 5. So now you really should be doing things like

Transform transform = GetComponent<Transform>();

variable called “transform” of class “Transform” populated with the result of the GetComponent() function with type(T) of the “Transform” class.

in the Awake()/Start() functions.

more details in the unity blog for this change here: http://blogs.unity3d.com/2014/06/23/unity5-api-changes-automatic-script-updating/

and yes, looks a lot like an inventory. You could look into something like ScriptableObjects to hold the available job data too.

Scriptable Object like an Object with a script attached? that’s what I was thinking making an object for each Job and then somehow making it so the above image gets all the job data from that object I’m just not sure how to actually make it so it checks as I could easily do it for one object

using UnityEngine.UI;

playerJobrole playerJobrole;
public Text jobHP;

void Update () {
      jobHP.text = playerJobrole.curJobHP.ToString();
}

But that doesn’t allow me to add different jobs to the system, i done the above and it displays the health from the other script perfectly fine but seems I don’t know how to make it so it can get multiple scripts instead of just one… Haha I might just leave it to be honest and think of a different system no point trying to do something I have no clue about

ScriptableObject the class; they’re kind of like a GameObject but don’t support functions, just data… Home | BurgZerg Arcade

That does sound like an easier way totally understand how its working, but it doesn’t mention anything about getting the data from the other scripts… If that makes sense so say I do something along the lines of what hes shown in the video, how would I get the weapons stats

sorry to be a bother like lol just trying to get my head around this as fast as so I can carry on with the game lol dont wanna rush but dont wanna wait around in the dark either if you get me haha

if weaponDB is the reference to the ScriptableObject holding all the weapon data from the above link, you’d get the weapon with something like this:

Weapon myWeapon = weaponDB.Weapon(1); // get the second weapon (list starts at 0)

the “trick” would be creating the buttons from the ScriptableObject list such that they know their index integer values. You could do this by setting the List in the ScriptableObject as public and for a simple “for each thing in list add button” approach, or keep the list private and do a “for” loop from int = 0 to < db.COUNT

Would this be better for me to learn from as it looks like it would be :slight_smile: