freddyatlantis
Member
Hi,
I have the script below, used to damage player health. The script works fine if used on an object which is created in the editor, but when using the script on a prefab which is instantiated at runtime, I get the following error:
Does anyone know where to point me to get this solved? Am I approaching this incorrectly?
I have the script below, used to damage player health. The script works fine if used on an object which is created in the editor, but when using the script on a prefab which is instantiated at runtime, I get the following error:
The script is as follows:UnassignedReferenceException: The variable m_Transform of CharacterHealth has not been assigned.
You probably need to assign the m_Transform variable of the CharacterHealth script in the inspector.
UnityEngine.Transform.get_position () (at <86acb61e0d2b4b36bc20af11093be9a5>:0)
Opsive.UltimateCharacterController.Traits.Health.Damage (System.Single amount) (at Assets/ExternalPackages/Opsive/UltimateCharacterController/Scripts/Traits/Health.cs:206)
DealDamage.OnTriggerEnter (UnityEngine.Collider other) (at Assets/OpsiveScriptMods/Damage/DealDamage.cs:17)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Opsive.UltimateCharacterController.Traits;
public class DealDamage : MonoBehaviour
{
[Tooltip("The character that has the health component.")]
[SerializeField] protected GameObject m_Character;
public float m_DamageAmount = 10;
public void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
var health = m_Character.GetComponent<Health>();
health.Damage(m_DamageAmount);
}
}
}
Does anyone know where to point me to get this solved? Am I approaching this incorrectly?