No, I don't think I can do it. I tried by reading a little bit of those two pages which try to do something similar, I think.
https://www.opsive.com/forum/index.php?threads/onobjectimpact-event-not-firing.1418/
https://www.opsive.com/forum/index.php?threads/real-blood.3742/
I asked Chat GPT so many things (poor thing), I even gave it pieces of code with the definitions for health and onobjectimpact. But it always makes errors.
Here is my latest test, but it gets stuck on Hitcollider, which it doesn't recognize for the ImpactCallBackContext class.
To you, this must be nonsense.
C#:
using UnityEngine;
using UnityEngine.Events;
using Opsive.Shared.Inventory;
#if ULTIMATE_CHARACTER_CONTROLLER_MULTIPLAYER
using Opsive.Shared.Networking;
using Opsive.UltimateCharacterController.Networking.Traits;
#endif
using EventHandler = Opsive.Shared.Events.EventHandler;
using Opsive.UltimateCharacterController.Items.Actions.Impact;
using Opsive.UltimateCharacterController.Traits;
public class CustomDamageReceiver : MonoBehaviour
{
[SerializeField] protected UnityEvent m_OnObjectImpact;
[SerializeField] protected bool m_DebugLogImpact;
[SerializeField] protected ItemDefinitionBase[] m_AllowedWeapons;
private void Awake()
{
EventHandler.RegisterEvent<ImpactCallbackContext>(gameObject, "OnObjectImpact", OnObjectImpact);
}
private void OnObjectImpact(ImpactCallbackContext ctx)
{
// Vérifiez si l'arme est autorisée
if (IsAllowedWeapon(ctx.CharacterItemAction?.CharacterItem?.ItemDefinition))
{
// Obtenez le composant endommageable de l'arbre et infligez des dégâts
var health = ctx.HitCollider.GetComponent<Health>();
if (health != null)
{
health.Damage(ctx);
}
}
// Déclenchez l'événement UnityEvent
m_OnObjectImpact.Invoke();
// Afficher un message de débogage si nécessaire
if (m_DebugLogImpact)
{
Debug.Log(ctx);
}
}
private bool IsAllowedWeapon(ItemDefinitionBase itemDefinition)
{
// Vérifiez si l'ItemDefinition de l'arme est autorisé
foreach (var allowedWeapon in m_AllowedWeapons)
{
if (allowedWeapon == itemDefinition)
{
return true;
}
}
return false;
}
}
But for me, it's a bit like Chinese. I'm trying to understand. Yet what I want to do, in my imagination, is simple, but if you don't know all the definitions and the code simply, it's torture.
I've already spent 6 months trying to understand 10% of UCC.
Now I understand a little bit about Inventory. I'm using what's already created to copy and paste a new one and make it work.
But since you haven't done the UIS integration demo like the UCC demo with all the weapons, and the UIS integration demo doesn't have everything like the normal UIS, the depot or upgrade, for example (which I haven't done yet, failed once).
I feel like I'm spending my months just trying instead of moving forward using the demos.
I've watched all the videos several times, but since I'm watching your actions with my eyes and not listening, since I don't understand spoken English, I think you sell your projects saying that people must know a minimum.
But since it's super complex to understand, as soon as we have to do our own code, it's a headache. Except for developers.
Sorry for this long text, I wanted to tell you my feeling as an amateur and beginner in Unity.