- Home /
I want to make damage calculation that only takes Health, Damage, Resistance. But my code is i must declare the damage calculation manually. Can i make it like Health - Damage - (0.5f * Resistance) instead?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ObjectStats : MonoBehaviour
{
public struct Status
{
public float Health;
public float Resistance;
public float Damage;
public int Stugger;
}
public Status MainCharacter;
public Status Enemy;
void ObjectStatus()
{
MainCharacter.Health = 100;
MainCharacter.Resistance = 30;
MainCharacter.Damage = 30;
Enemy.Health = 100;
Enemy.Resistance = 30;
Enemy.Damage = 20;
float damagedeal;
float resist;
damagedeal = Enemy.Health - MainCharacter.Damage;
resist = damagedeal + (0.5f * Enemy.Resistance);
Debug.Log(resist);
}
void Update()
{
if (Input.GetKeyDown("f"))
{
ObjectStatus();
}
}
}
I am sorry, but I am not really sure what you are trying to achieve...
Yes you can make it anything you want, it's your code.. What is preventing you from doing the way you want? What issues are you having? What results do you want?
Answer by Vazgi · Sep 08, 2021 at 11:22 AM
First your code looks bad. You must be new to programming. if you are dealing dmg to the enemy the code should be something like this.
Enemy.Health = Enemy.Health - MainCharacter.Damage (0.5f Enemy.Resistance);
Next time give more information of what you want to do as I am not sure if I used the right formula to calculate the dmg.
Your answer
Follow this Question
Related Questions
DataBase creation on android via unity 1 Answer
Recieve Shadow from a camera culled Object 1 Answer
How to change smoothness of a material in scripts? 1 Answer
Load new scripts (post-build) through Asset Bundles. Is this even possible? 0 Answers
Spawning fireballs at a certain point,Spawning Fireballs at a certain location 1 Answer