So a few days ago I was trying to figure out a combat system tutorial, and it never really worked out. Then I started getting excited about coding since thank God I was able to learn how to write a couple of simple codes and modify a few others. Decided to try and write a combat script, and think I’m close, but am humbly asking for help getting over the hump. Here’s how I see it working:
Code A attaches to the sword. When the sword collides with something tagged “enemy” it takes off a certain amount of the enemy’s health.
Code B is attached to the enemy, (actually is attached to an empty game object that the enemy is a child of) and is simply a variable stating said enemy’s health.
I am aware that either code may not be complete, may be sloppy, etc. Trial and error, as I’m so new to this. And help is greatly appreciated. Thanks, and God bless.
Code A:
function onCollisionEnter(Collision)
{
target = GameObject.FindWithTag("Enemy").transform;
}
function Update () {
}this.enemyHealth -=50;
if(this.enemyHealth <= 0) {
Destroy(this.gameObject);
}
Code B:
var enemyHealth : int = 100;