void Pain() { if (painFinished < Time.time) { if (SFXPainClip != null) { SFX.PlayOneShot(SFXPainClip); } float r = Random.Range(0, 1); if (r < 0.34) { currentPainAnim = painSelection.Pain1; } else { if (r < 0.67) { currentPainAnim = painSelection.Pain2; } else { currentPainAnim = painSelection.Pain3; } } switch (currentPainAnim) { case painSelection.Pain1: anim.Play("Pain1"); break; case painSelection.Pain2: anim.Play("Pain2"); break; case painSelection.Pain3: anim.Play("Pain3"); break; } painFinished = Time.time + timeBetweenPain; } }
void Start() { healthManager = GetComponent <HealthManager>(); rbody = GetComponent <Rigidbody>(); SFX = GetComponent <AudioSource>(); anim = GetComponent <Animation>(); //Setup colliders for NPC and its corpse if (normalCollider == corpseCollider) { Debug.Log("ERROR: normalCollider and corpseCollider cannot be the same on NPC!"); return; } switch (normalCollider) { case collisionType.Box: boxCollider = GetComponent <BoxCollider>(); boxCollider.enabled = true; break; case collisionType.Sphere: sphereCollider = GetComponent <SphereCollider>(); sphereCollider.enabled = true; break; case collisionType.Mesh: meshCollider = GetComponent <MeshCollider>(); meshCollider.enabled = true; break; case collisionType.Capsule: capsuleCollider = GetComponent <CapsuleCollider>(); capsuleCollider.enabled = true; break; } switch (corpseCollider) { case collisionType.Box: boxCollider = GetComponent <BoxCollider>(); boxCollider.enabled = false; break; case collisionType.Sphere: sphereCollider = GetComponent <SphereCollider>(); sphereCollider.enabled = false; break; case collisionType.Mesh: meshCollider = GetComponent <MeshCollider>(); meshCollider.enabled = false; break; case collisionType.Capsule: capsuleCollider = GetComponent <CapsuleCollider>(); capsuleCollider.enabled = false; break; } currentState = Const.aiState.Idle; //currentWaypoint = 0; tick = 0.05f; // Think every 0.05f seconds to save on CPU idealTransformForward = transform.forward; enemy = null; attacker = null; firstSighting = true; inSight = false; goIntoPain = false; dyingSetup = false; hopDone = false; idleTime = Time.time + Random.Range(3f, 10f); attackFinished = Time.time + 1f; tickFinished = Time.time + tick; timeTillDeadFinished = Time.time; firingFinished = Time.time; painFinished = Time.time; fireDelayFinished = Time.time; currentPainAnim = painSelection.Pain1; if (SFX == null) { Debug.Log("WARNING: No audio source for npc at: " + transform.position.x.ToString() + ", " + transform.position.y.ToString() + ", " + transform.position.z + "."); hasSFX = false; } else { hasSFX = true; } if (healthManager.health > 0) { if (walkWaypoints.Length > 0 && walkWaypoints[0] != null) { currentState = Const.aiState.Walk; // If waypoints are set, start walking to them } else { currentState = Const.aiState.Idle; // Default to idle } } deathBody.SetActive(false); normalBody.SetActive(true); collisionAid1.SetActive(true); collisionAid2.SetActive(true); }