Hi, I am pretty new to scripting with unity in general, but have been using ORK for some time now. However I am trying to learn scripting as well as do things with the ORK API and such.
Currently I am trying to make a simple script that changes the weapon displayed on my combatant based on what is equipped in his inventory. I know their may be several non-scripting ways to accomplish this, but I am trying to use this a learning experience.
Currently I have the weapon object childed to my combatants prefab.
I would like it to be so when I equip my weapon in the inventory the script will then enable the object making it visible on my combatant and if I change any weapon it will disable and enable those components based on what I have equipped.
Again I am very new to the javascript syntax with unity so I am even more so clueless on how to script with ORK exactly. I was mostly just hoping for some structure help and how I should go about setting it up.
Anything is appreciated, thanks in advance! :)
The code is included in the full version if you want to check it out.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Yes im pretty aware of the equipment viewer, but I actually wasn't to crazy about the process I had to go through to set my equip to the right position.
Also(and maybe you can help with this too). I am making the weapon be displayed in and outside of combat(outside on his back, inside in his hands). So I am not sure how to get it to display and move to different positions with the viewer. im certain with this I am just not doing something that I dont know though so any comments on that is appreciated too.
But anyway, I was really hoping to try and script this to learn how to use some thing with the API mostly, I know there is other ways, but I just thought this could be easy and fun. Not trying to negate the advice you gave me though I really do appreciate it!
Ok, I guess you guys are basically telling me, im trying to do things the hard way haha. Guess I will just do this after all then. Thanks for the help. Can anyone leave any scripting advice with ork though? I checked the tutorials and all, but still left feeling a bit confused when i was going through the API.
E.g. the where is what how-to can be useful for starters :)
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
I was wondering what would need to do to make the script Check if the player has a certain weapon equipped and then if it does will enable the mesh render of an object(i have the later down, just need to know how to do the first part with the ORK functions.)
combatant.Equipment[int index]
index is the ID of the equipment part (i.e. it's index in the list in the editor).
This gives access to the equipment part with additional functionality to access the weapon that's equipped there.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Here is my code so far. You can ignore the bottom bit for now. Im sorta doing it backwards to test to make sure changes are made when the combatant does have the weapon equipped.(but if you can understand whats going on then please dont hesitate to help on that too)
#pragma strict
using ORKFramework ;
using ORKFramework.Behaviours ;
CombatantComponent combatantComponent = dpt_sword_boy_PF;
GetComponent<CombatantComponent>() ;
if(combatantComponent != null)
{
Combatant combatant = combatantComponent.combatant;
}
function Update ()
{ if (combatant.Equipment[int 4])
{
GetComponent(MeshRenderer).enabled = false;
]
}
Put finding the combatant in the Start function of the component (void Start()) and make the combatant a field of the class to have it accessible in the update function.
Checking if something is equipped on the part is done like this:
if(combatant.Equipment[4].Equipped && combatant.Equipment[4].Equipment != null)
To check what's actually equipped on there, you'll access the Equipment property of the equipment part (what's used as a 2nd check in the if statement).
This is the EquipmentShortcut class that holds the data of the equipped weapon/armor - you can check the ID and type (weapon/armor) of it.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
Is any of this what you met? (thanks for having a lot of patience with me)
#pragma strict
using ORKFramework ;
using ORKFramework.Behaviours ;
public class weapon viewer : MonoBehaviour
function Start()
{
(void Start(
CombatantComponent combatantComponent = dpt_sword_boy_PF;
GetComponent<CombatantComponent>() ;
if(combatantComponent != null)
{
Combatant combatant = combatantComponent.combatant;
}
)
)
function Update ()
{
if (combatant.Equipment[int 4].Equipped && combatant.Equipment[4].equipment != null)
{
GetComponent(MeshRenderer).enabled = false;
}
}
If this is C# (what it looks like to be), you wont be using stuff like function Start() or function Update(), but void Start() and void Update() instead.
The MonoBehaviour class you're extending from will make this script a component that can be attached to game objects - the Start function will be called when the object is added to the scene, the Update function every frame.
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!
How is this looking? And your right I was doing javascript, but now I switched to C#:
using UnityEngine;
using System.Collections;
using ORKFramework;
using ORKFramework.Behaviours;
public class weaponviewer : MonoBehaviour {
public GameObject Obj;
// Use this for initialization
void Start () {
CombatantComponent combatantComponent = gameObject.
GetComponent<CombatantComponent> ();
if (combatantComponent != null) {
Combatant combatant = combatantComponent.combatant;
}
}
// Update is called once per frame
void Update () {
MeshRenderer w = Obj.GetComponent<MeshRenderer>();
if (combatant.Equipment[4].Equipped && combatant.Equipment[4].equipment != null)
{
w.enabled = false;
}
}
}
If you're enjoying my products, updates and support, please consider supporting me on patreon.com!