Quantcast
Channel: Questions in topic: "enemy"
Viewing all articles
Browse latest Browse all 1488

How to have an NPC with multiple parts detect damage

$
0
0
I have an enemy NPC built from several simple game objects (cubes, cylinders, etc.). I have followed a tutorial in making enemies take damage if they're within a certain range, and the code works fine on single objects. I have tried both placing all of the objects into an empty object and having them saved as a prefab, then applying the code to them, but when I play the game and attack the enemy, the health remains unchanged. Code: Attack code within Main character: #pragma strict var Damage:int = 25; var Distance:float; var enemyDistance:float = 2; function Update() { if(Input.GetButtonDown("Fire1")) { var hit:RaycastHit; if(Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit)) { Distance=hit.distance; if(Distance

Viewing all articles
Browse latest Browse all 1488

Trending Articles