I’ve been learning C# programming for about 4 weeks (Literally just started programming 4 weeks ago, never did it before), watched tutorials after tutorials, messed with code and read descriptions after descriptions. So here I am trying to setup a stat system for my game… Trying to keep this short:
I was trying to make it so I didn’t need a separate script for every character / enemy in my game but I gave up and just made separate scripts. (If any of you know how to achieve what I was trying to achieve I’d love to be pointed in the right direction).
So now I have a script for my character and enemy. Now it seems that the stats are calculating okay, but the debug.log is showing that my character is being hit TWICE and no matter how much I stare at this code, I can’t figure out why that’s happening.
On top of those two questions… Could anyone look at my code briefly and tell me if it’s bad? Suggestions? Is there an easier way to do this? Another thing that I think is a problem is that at the start of the void, it calculates some of my statistics, I think this might cause unintentional stat gain but I have no idea how to set this up otherwise. It’s all kinda messy right now because I am only concerned with it working before I start fixing stats properly though if something seems erroneous it would be REALLY appreciated if someone pointed out.
Kai’s stats in editor: http://puu.sh/8HLvr/5272c74624.png
Enemy’s stats in editor: http://puu.sh/8HLwn/56f80dcd92.png
using UnityEngine;
using System.Collections;
public class battleStart : MonoBehaviour {
public kaiStats Kai;
public enemycubeStats statsofCube;
public bool battleBegin = false;
void Start ()
{
// Enemy's Stats
statsofCube.physicalAttack = statsofCube.strength * 0.5f + statsofCube.weaponDamage;
statsofCube.magicAttack = .5f * statsofCube.intelligence;
statsofCube.hitChance = statsofCube.hitChance;
statsofCube.dodge = statsofCube.agility * (Random.Range (0.1f, 0.3f));
// Kai's Stats
Kai.physicalAttack = Kai.strength * Kai.weaponDamage;
Kai.magicAttack = .5f * Kai.intelligence;
Kai.hitChance = Kai.hitChance * (Random.Range (0.1f, 0.5f));
Kai.dodge = Kai.agility * (Random.Range (0.1f, 0.3f));
}
void Update()
{
if (Input.GetKeyDown ("g"))
{
battleBegin = true;
while (battleBegin) {
Kai.currentHealth -= Kai.defense - statsofCube.physicalAttack;
battleBegin = false;
}
Debug.Log (Kai.currentHealth);
}
}
}
using UnityEngine;
using System.Collections;
public class kaiStats : MonoBehaviour {
public float
level,
maxHealth,
currentHealth,
strength,
intelligence,
agility,
defense,
magicDefense,
hitChance,
dodge,
magicAttack,
physicalAttack,
weaponDamage;
}
using UnityEngine;
using System.Collections;
public class enemycubeStats : MonoBehaviour {
public float
level,
maxHealth,
currentHealth,
strength,
intelligence,
agility,
defense,
magicDefense,
hitChance,
dodge,
magicAttack,
physicalAttack ,
weaponDamage;
}
Thanks so much to anyone who can help me make this not suck. I really think if I can just be shown where I’m messing up and what code isn’t going to work, it will help me a lot.