OK, I got the AI to damage the player, but now I have 2 issues. First, after applying damage to the Health trait that takes the player under 0, the player doesn't die. I would have thought that would have occurred automatically, but it doesn't. What should I do to insure the player dies when the health is below zero?
Second, when I modified my script for the player to damage the AI, it crashes. Previously I had to provide the name of a Damage callback function in the weapon Impact Options, but that no longer seems to exist. I found code in the Melee script that calls OnObjectImpact so I modified my code to use that named function. Here is the code:
Code:
public class OpsiveBridge : MonoBehaviour
{
private Emerald_AI _emeraldAI;
private void Awake()
{
_emeraldAI = GetComponent<Emerald_AI>();
EventHandler.RegisterEvent<float, Vector3, Vector3, GameObject>(this.gameObject, "OnObjectImpact", OnObjectImpact);
}
private void OnObjectImpact(float amount, Vector3 point, Vector3 normal, GameObject originator)
{
if (_emeraldAI != null)
{
_emeraldAI.Damage((int)amount, Emerald_AI.TargetType.Player);
Debug.Log(this.name + " took " + amount + " damaged at location " + point + " with normal " + normal + " from object " + originator);
}
}
}
However, when I shoot it with the gun, it just crashes with the following error:
NullReferenceException: Object reference not set to an instance of an object
Opsive.UltimateCharacterController.Events.EventHandler.ExecuteEvent[Single,Vector3,Vector3,GameObject,Collider] (System.Object obj, System.String eventName, Single arg1, Vector3 arg2, Vector3 arg3, UnityEngine.GameObject arg4, UnityEngine.Collider arg5) (at Assets/Opsive/UltimateCharacterController/Scripts/Events/EventHandler.cs:535)
Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.HitscanFire (Single strength) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/ShootableWeapon.cs:906)
Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.Fire (Single strength) (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/ShootableWeapon.cs:692)
Opsive.UltimateCharacterController.Items.Actions.ShootableWeapon.UseItem () (at Assets/Opsive/UltimateCharacterController/Scripts/Items/Actions/ShootableWeapon.cs:621)
Opsive.UltimateCharacterController.Character.Abilities.Items.Use.LateUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/Abilities/Items/Use.cs:580)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.LateUpdateActiveAbilities (Opsive.UltimateCharacterController.Character.Abilities.Ability[] abilities, System.Int32& abilityCount) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:843)
Opsive.UltimateCharacterController.Character.UltimateCharacterLocomotion.LateUpdateUltimateLocomotion () (at Assets/Opsive/UltimateCharacterController/Scripts/Character/UltimateCharacterLocomotion.cs:831)
Opsive.UltimateCharacterController.Character.CharacterLocomotion.Move (Single horizontalMovement, Single forwardMovement, Single deltaYawRotation) (at Assets/Opsive/UltimateCharacterController/Scripts/Character/CharacterLocomotion.cs:476)
Opsive.UltimateCharacterController.Game.DeterministicObjectManager+DeterministicCharacter.FixedMove () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/DeterministicObjectManager.cs:146)
Opsive.UltimateCharacterController.Game.DeterministicObjectManager.FixedUpdate () (at Assets/Opsive/UltimateCharacterController/Scripts/Game/DeterministicObjectManager.cs:590)
So, I’m not quite doing something right, but not sure what. This is basically the same thing I had before except previously I had to specify the name of the event and then I registered for that event. Maybe OnObjectImpact is not the correct event, but I can’t find anything else yet.
Thanks