C# how to make other script apply the damage

i didn’t get any errors but it won’t apply the damage.

this is the script:

using UnityEngine;
using System.Collections;

public class ZombieScript : MonoBehaviour {
	
	public int health = 100;
	private int damage;
	private float time;
	private float hrdelay = 0.5f;
	public int healthRegen = 1;
	
	// Use this for initialization
	void Start () {
	
	}
	
	
	public void Damage (int damageParam){
		damage = damageParam;
	}
	
	// Update is called once per frame
	void Update () {
	health = health - damage;
	damage = 0;
	if (Time.time > time)
		{
		time = Time.time + hrdelay;
		health = health + healthRegen;
		}
	}
}

You need to be more specific about what is wrong. I can only presume you intend for Damage() to be called from another script. And then it applies the damage the Zombie’s update.

If so the problem is likely that you meant:

 public void Damage (int damageParam){
       damage += damageParam;
 }

In your version, if multiple things damage the zombie only the last would take effect. And if, say, something called it with 0, then that would cause all previous damage to not take effect that frame.

By using += it’ll work right.

But since you didn’t provide more detail, this is the best debugging that can be done based on what you have in your question.