|
We have been working on a script that shoots a raycast from the main camera, and in theory, if it hits an object tagged "enemy", the enemy will die. The problem is, that once one "enemy" is killed, all objects tagged "enemy" are also destroyed. Here are the two scripts we use:
Then, our AIhealth script:
(comments are locked)
|
|
As I see the problem you have attached the script AIhealth to all enemies in the scene. Thus by accessing a static variable all the enemies are damaged. Alternatively you could send a message to the enemy that was hit. This is c# code for the first script
using System.Collections; public class raycastshot : MonoBehaviour { public float bulletDamage = 50; public float range = 10000; public RaycastHit hit;
} Then for the AIhealth script
using System.Collections; public class AIhealth : MonoBehaviour { public float AIHEALTH = 100;
} Now every enemy should have its own health.
(comments are locked)
|
