I have a enemy-prefab with a EnemyHealthController. In the EnemyHealhController there is a public Script-Variables for two different GameObjects.
Now when I instantiate a new enemy-prefab to the current scene, the variables are unassigned. I would that the
variable should assigned to the Player in the current scene without drag and drop or select. Is there a solution to solve this problem?
From this:
to this:
The public Scripts-Variables are:
public EnemyCount enemycount;
public ExpSystem expSystem;
EnemyHealthController:
using UnityEngine;
using System.Collections;
public class EnemyHealthController : MonoBehaviour {
public float currentHealth = 2;
public float DamageEffectPause = 0.2F;
public ExpSystem expSystem;
public EnemyCount enemycount;
void ApplyDamage(float damage)
{
if (currentHealth > 0)
{
currentHealth -= damage;
if (currentHealth <= 0)
{
currentHealth = 0;
Die();
}
else
{
StartCoroutine(DamageEffect());
}
}
}
IEnumerator DamageEffect()
{
renderer.enabled = false;
yield return new WaitForSeconds(DamageEffectPause);
renderer.enabled = true;
yield return new WaitForSeconds(DamageEffectPause);
renderer.enabled = false;
yield return new WaitForSeconds(DamageEffectPause);
renderer.enabled = true;
yield return new WaitForSeconds(DamageEffectPause);
renderer.enabled = true;
}
void Die()
{
expSystem.curEXP += 10;
enemycount.enemyCount--;
Destroy (gameObject);
}
}