#How do I call the function?

1 messages · Page 1 of 1 (latest)

trail shard
#

Script that calls the function(Attached to GameObject):

using UnityEngine;


public class Strong_Punch_Card : MonoBehaviour, IAbility_Use
{
    private Hitbox_Module HitBoxM_Reference;

    private void Awake()
    {
        HitBoxM_Reference = new Hitbox_Module();
    }

    public void Use_Ability(Humanoid_Stats Entity_Stats)
    {
        if (Entity_Stats.StunnedTime > 0 || Entity_Stats.IsUsingAbility == true) return;

        GameObject Character = Entity_Stats.gameObject;

        Vector3 HPosition = Character.transform.position + Character.transform.forward * 2;
        Vector3 HSize = new Vector3(2f, 2f, 3f);
        Quaternion HRotation = Character.transform.rotation;

        Collider[] HitboxReturns = HitBoxM_Reference.Create_Box_Hitbox(HPosition, HSize, HRotation);
    }
}

Script that has the function(not attached to any GameObject):

using UnityEngine;
using UnityEngine.TextCore.Text;

public class Hitbox_Module : ScriptableObject
{
    public GameObject Box_Hitbox;

    public Collider[] Create_Box_Hitbox(Vector3 Size, Vector3 Position, Quaternion Rotation)
    {
        if (Box_Hitbox == null || Size == null || Position == null) return null;


        Collider[] HitBox_Victims = Physics.OverlapBox(Position, Size/2, Rotation);

        if (Box_Hitbox != null)
        {
            GameObject NewHitBox = Instantiate(Box_Hitbox, Position, Rotation);
            NewHitBox.transform.localScale = Size;
        }



        return HitBox_Victims;
    }
}
vague maple
#

assuming you mean Create_Box_Hitbox, well, you have a reference to a Hitbox_Module, so just call it on that

#

you seem to already be doing that...

trail shard
#

It does seems like that, but then what is the reason for this error?

trail shard
# trail shard

Here is where the error happens, line 25: cs Collider[] HitboxReturns = HitBoxM_Reference.Create_Box_Hitbox(HPosition, HSize, HRotation);

trail shard
#

I will try something tomorrow

vague maple
#

also for future reference,

#

!code

harsh windBOT
trail shard
#

I cant drag it there using public

vague maple
trail shard
#

and I cant drag the script asset there

#

Attaching it to an empty will allow me to reference it, yet the script that needs it is in assets too

vague maple
#

are you just doing AddComponent

#

or what

vague maple
#

then you can assign it on the prefab

#

the prefab is a gameobject too

#

it's just not a gameobject in the scene

trail shard
vague maple
#

that's the thing with the component, isn't it

trail shard
#

Actually that

#

is genius

#

thanks

#

I guess that is all

vague maple
#

this is normal serialized references lol