I have been attempting to write a collection of scripts that deals with player health and an enemy object hitting a player object. This script is placed in a hitbox child of the enemy object and refers to a player health script which seems to be working correctly. When I approach the enemy however, Unity freezes up completely. I know that it is most likely some sort of loop or condition that is executing infinitely with little to no delay but I cannot seem to pinpoint exactly what it is. Most of the pieces of the script are modeled off of snippets of code that I have used before that worked so I am not quite sure exactly what the issue is. Any help would be appreciated. Here is the script.
#pragma strict
public var damageDone: float = 45f;
public var hitCoolDownTime: float = 1f;
public var meshObject: GameObject;
private var playerObject: GameObject;
private var playerHitBox: GameObject;
private var playerState: PlayerState;
private var hitCoolDown: boolean = false;
private var hitTimer: float = 0f;
//Crashes the game
function Awake () {
playerObject = GameObject.FindGameObjectWithTag("Player");
playerState = playerObject.GetComponent(PlayerState);
}
function Update () {
if(hitCoolDown){
hitTimer += Time.deltaTime;
if(hitTimer >= hitCoolDownTime){
hitCoolDown = false;
hitTimer = 0f;
}
}
}
function OnTriggerEnter (other: Collider){
if(other.gameObject == playerObject && !hitCoolDown && meshObject.GetComponent(SkinnedMeshRenderer).enabled){
playerState.Damage(damageDone);
hitCoolDown = true;
}
}
↧