unity3d - RaycastHit Randomly Gets 2 Hits -
i've been following tutorial online while , far gone pretty well. problem have raycasthit. @ first glance seems working pretty well, every , seems if 2 hits. have set every time press mouse button, animation go off player swinging club , ray sent player(actually gameobject parented first person camera) enemy. instead of gameobject being destroyed in 2 hits, every , then, destroyed in one.
#pragma strict var thedamage : int = 50; var distance : float; var maxdistance : float = 1.5; var thesystem : transform; function update () { if(input.getbuttondown("fire1")) { animation.play("attack"); } } function attackdamage () { var hit : raycasthit; if(physics.raycast (thesystem.transform.position, thesystem.transform.transformdirection(vector3.forward),hit)) { distance = hit.distance; } if (distance < maxdistance) { enemylogic.applydamage(thedamage); } }
&&
#pragma strict static var health = 100; function update () { if (health <= 0) { dead (); } } static function applydamage (thedamage: int) { health -= thedamage; } function dead () { destroy (gameobject); }
Comments
Post a Comment