Deal damage (damage_manager)
Hi guys! I have problem with my damage_manager script, he should receive information from a opponent script. unfortunately I don't know where Im doing wrong. Im attaching two scripts. Manager script:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class damage_manager : MonoBehaviour
{
//public float health;
public static float damage;
private float armor_dmg;
private float health_dmg;
void FixedUpdate()
{
//if (health <= 0)
//{
// Destroy(gameObject);
//}
}
void OnCollisionEnter(Collision hit)
{
player_mechanics stats = GetComponent<player_mechanics>();
if (hit.gameObject.tag == "Enemy")
{
armor_dmg = damage * 0.7f;
health_dmg = damage * 0.3f;
Debug.Log(stats.Armor + " " + stats.Health + " " + health_dmg + " " + armor_dmg);
if (stats.Armor > 0)
{
if (stats.Armor >= armor_dmg)
{
stats.Armor -= armor_dmg;
stats.Health -= health_dmg;
}
else
{
stats.Health -= ((armor_dmg - stats.Armor) * 0.5f + health_dmg);
stats.Armor = 0;
}
}
else
{
stats.Health -= damage;
}
if (stats.Health < 0)
{
stats.Health = 0;
}
}
}
}
This is the second script where i want to set damage:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class damage_test : MonoBehaviour
{
public float Damage_value;
private void Update()
{
damage_manager.damage = Damage_value;
}
The end result should be that each damage script should send its own damage information to the manager script. Thank you for any help :)
Answer by Robb_oates · Aug 08, 2021 at 08:24 AM
i think you need to declare the damage manager script with either "getcomponent" or set it in the inspector. and they both will send but the first one to send will be overwritten by the second as you only have 1 variable.
Your answer
![](https://koobas.hobune.stream/wayback/20220613024935im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Damage manager (ThirdPersonShooter) 1 Answer
Timer System in GameManager with two lists 0 Answers
Can the viewport rect of a camera be static? 0 Answers
Static class in Unity 2 Answers
Question About Defining and Calling Static Variables 1 Answer