Scriptable Object add damage not working
I have a scriptable object which stores enemy damage and a function addDamage. The addDamage function is called on my enemy object if it collided with player. However the addDamage function seem to not work, the player health is not decreasing based on the enemy damage. I have been trying to make this work out and I'm at my last ropes before I throw my laptop in the window.
This is my scriptable object script for my enemy object where it is attached on, There are two types of enemy I have created, one has a low damage value and the other has a high damage value, so I created two CreateAssetMenu for each enemy. :
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[CreateAssetMenu(menuName = "Character")];
public class CharacterScriptables : ScriptableObject
{
public int Health;
public int Damage;
public float speed;
bool isbeingHeld = false;
public void addDamage(int Playerhealth) {
Playerhealth -= Damage;
if (Playerhealth <= 0)
{
Debug.Log("EnemyDestroyed");
return;
}
}
}
This is my enemy script where the Ontrigger script is written:
using System.Collections; using System.Collections.Generic; using UnityEngine; public class EnemyScript : MonoBehaviour { public CharacterScriptables enemy; // the reference to my scriptable object public PlayerHealthSystem Char; // the reference to my player health void Start() { } void OnTriggerEnter2D(Collider2D target) { if (target.tag == "Player") { enemy.addDamage(Char.p_health); Debug.Log(Char.p_health); } } }
here is my player script
using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerHealthSystem : MonoBehaviour { public CharacterScriptables cs; [HideInInspector] public int p_health = 90; void Awake() { Debug.Log(p_health); } void Start() { } }
Your answer
Follow this Question
Related Questions
How to combine two colliders into one 0 Answers
publishing unity game to playstore,launching unity app to playstore ! 1 Answer
Mesh not being rendered in build 0 Answers
Unity job is failed error. 0 Answers