why did the events I made below not work?

Reza

Member
why did the events I made below not work? is there something wrong? I tried to hit a collider with a weapon but it did not bring up the debug that I made



Code:
using UnityEngine;

using Opsive.Shared.Events;



public class HarvestManager : MonoBehaviour

{

    /// <summary>

    /// Initialize the default values.

    /// </summary>

    public void Awake()

    {

        EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject, object, Collider>(gameObject, "OnObjectImpact", OnImpact);

    }



    /// <summary>

    /// The object has been impacted with another object.

    /// </summary>

    /// <param name="amount">The amount of damage taken.</param>

    /// <param name="position">The position of the damage.</param>

    /// <param name="forceDirection">The direction that the object took damage from.</param>

    /// <param name="attacker">The GameObject that did the damage.</param>

    /// <param name="attackerObject">The object that did the damage.</param>

    /// <param name="hitCollider">The Collider that was hit.</param>

    private void OnImpact(float amount, Vector3 position, Vector3 forceDirection, GameObject attacker, object attackerObject, Collider hitCollider)

    {

        Debug.Log(name + " impacted by " + attacker + " on collider " + hitCollider + ".");

    }



    /// <summary>

    /// The GameObject has been destroyed.

    /// </summary>

    public void OnDestroy()

    {

        EventHandler.UnregisterEvent<float, Vector3, Vector3, GameObject, object, Collider>(gameObject, "OnObjectImpact", OnImpact);

    }

}


sorry if I copy the script without using a code table because I don't know how to use it
 
Last edited:
I already know the problem where, I put it in a new object game, and it turns out the event only works if it is placed on the object being attacked. but this is very difficult for my condition because I use vegetation studio and the gameobject (vegetation) can't be added to the script, I want to make a weapon to cut down trees is there a solution for my case?
 
I tried it but it didn't answer my second question, what if I use Vegetation Studio, and I want to add the events how do I do that? because the tree from VS cannot be added to a custom script
 
VS only provides a collider that has tags, and I mean it must detect what collider hit the weapon using a script that must be on the character, without having to add the script to the collider(tree) hit from the weapon
 
The OnObjectImpact event is set up to be sent to the target object.

I'm unfamiliar with Vegetation Studio. I'm guessing it spawns a bunch of prefabs during run-time? If that's the case, you may be able to add the impact detection script to the prefab/s that it spawns, or even add them during run-time (you'd have to refer to the docs/support for VS for help with this). Another approach would be to have a manager that adds the impact detection script to the relevant objects during run-time based on tags/layers.

Impact detection can be used on any prefab with a collider; there's no other setup or configuration required.
 
okay I forgot about that now I can take the object from the tag using the script and then add the events component
 
Top