Message
Message
using System.Collections;
using UnityEngine;
using UnityEngine.AI;
[Serializable]
public class EnemyAIGranny : MonoBehaviour
{
[SerializeField]
private Transform
myTransform,
grannyEye,
target,
bedtargetTemp1,
bedtargetTemp2,
bedtargetTemp3,
coffintargetTemp4,
coffintargetTempBY,
cartargetTemp,
nav1,
nav2,
nav3,
nav4,
nav5,
nav6,
nav7,
nav8,
nav9,
nav10,
nav11,
nav12,
nav13,
nav14,
nav15,
nav16,
player,
playerPos,
PlayerCoffinPos,
PlayerCoffinBYPos,
PlayerCarPos,
bearTrapSP,
grannyRagdoll,
grannyForceRagdoll;
private GameObject
bedCam1,
bedCam2,
bedCam3,
coffinHead1,
coffinHead2,
carHead,
bastuDoor,
bastuBom,
Player,
animationHolder,
allBedButtons,
doorRay,
checkGround,
gameController,
playerHukaKnapp,
playerHukaKnappParent,
optionButton,
coffinLock,
coffinLockBY,
Spider,
bearTrap,
soundHolder1,
soundHolder2,
soundHolder3,
playerSounds,
grannySounds,
grannyDisaper,
grannyGoneNormalText1,
grannyGoneEasyText1,
grannyGoneHardText1,
grannyGoneExtremeText1,
grannyGoneEasyShotText,
grannyGoneNormalShotText,
grannyGoneHardShotText,
grannyGoneExtremeShotText,
grannyEyeColor,
teddyMusicHolder,
startCarButton,
forwardButton,
reverseButton,
engineOnSound,
engineOffSound,
engineStartSound,
ObjectHolder;
private float
bastuTimer,
bastuDoorTimer,
number,
speed,
bastuSafeTimer,
offScreenDot,
distanceWaypoint,
distance,
attackDistance,
timer,
timerSee,
timerSearch,
timerBed,
safeTimer,
seeClosedDoorTimer,
grannysVarSpeed,
grannysAnimSpeed,
grannyEyeColorTimer;
public EnemyAIGranny()
{
offScreenDot = 0.8f;
waypointStart = timerOnOff = true;
}
target = GameObject.Find(Nav).transform;
navComponent =
(NavMeshAgent)base.transform.GetComponent(typeof(NavMeshAgent));
player = GameObject.Find("Player").transform;
playerPos = GameObject.Find("Main Camera").transform;
nav1 = GameObject.Find("Nav1").transform;
nav2 = GameObject.Find("Nav2").transform;
nav3 = GameObject.Find("Nav3").transform;
nav4 = GameObject.Find("Nav4").transform;
nav5 = GameObject.Find("Nav5").transform;
nav6 = GameObject.Find("Nav6").transform;
nav7 = GameObject.Find("Nav7").transform;
nav8 = GameObject.Find("Nav8").transform;
nav9 = GameObject.Find("Nav9").transform;
nav10 = GameObject.Find("Nav10").transform;
nav11 = GameObject.Find("Nav11").transform;
nav12 = GameObject.Find("Nav12").transform;
nav13 = GameObject.Find("Nav13").transform;
nav14 = GameObject.Find("Nav14").transform;
nav15 = GameObject.Find("Nav15").transform;
nav16 = GameObject.Find("Nav16").transform;
navComponent.speed = 1.2f;
switch (PlayerPrefs.GetInt("DiffData"))
{
case 0:
case 4:
grannysVarSpeed = 4.3f;
grannysAnimSpeed = 2f;
break;
case 1:
grannysVarSpeed = 3f;
grannysAnimSpeed = 1.5f;
break;
case 2:
grannysVarSpeed = 5f;
grannysAnimSpeed = 2.7f;
break;
case 3:
grannysVarSpeed = 7f;
grannysAnimSpeed = 3.3f;
break;
}
}
grannyEyeColor.gameObject.GetComponent<Renderer>().material.color = new
Color(0.2264151f, 0f, 0f);
grannyEyeColorTimerOn = true;
grannyEyeColorTimer = 0f;
((fadeUpDownTeddyMusic)teddyMusicHolder.GetComponent(typeof(fadeUpDownTeddyMusic)))
.startFade = true;
}
else if (grannyEyeColorTimerOn)
{
grannyEyeColorTimer += Time.deltaTime;
if (grannyEyeColorTimer > 7f)
{
grannyEyeColorTimerOn = false;
grannyEyeColorTimer = 0f;
grannyEyeColor.gameObject.GetComponent<Renderer>().material.color = new
Color(0.1509434f, 0.1509434f, 0.1509434f);
((fadeUpDownTeddyMusic)teddyMusicHolder.GetComponent(typeof(fadeUpDownTeddyMusic)))
.startFade = false;
}
}
}
if (!hitByArrow && !hitByGun && !bastuKilled && !hitByCar)
{
int num = 0;
Quaternion rotation = base.transform.rotation;
rotation.x = num;
base.transform.rotation = rotation;
if ((bool)target)
{
distanceWaypoint = Vector3.Distance(target.position,
base.transform.position);
}
distance = Vector3.Distance(playerPos.position,
grannyEye.transform.position);
}
if (playerGetCaught && playerFallDeath)
{
navComponent.speed = 0f;
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
if (!playerGetCaught)
{
if (!hitByArrow && !hitByGun && !bastuKilled && !hitByCar &&
target == null)
{
target = nav1;
}
if (!grannyIsFollow && !grannyLookUnderBed && !playerGetCaught &&
!hitByArrow && !hitByGun && !bastuKilled && !hitByCar)
{
safeTimer += Time.deltaTime;
if (safeTimer >= 80f)
{
safeTimer = 0f;
if (target.name != "Player")
{
grannyHearObject = false;
grannyHearPlayer = false;
number = UnityEngine.Random.Range(1, 33);
NewNav();
}
}
}
if (!playerGetCaught)
{
if (hitByArrow)
{
if (!ragdollSpawn)
{
ragdollSpawn = true;
navComponent.speed = 0f;
base.gameObject.tag = "Untagged";
animationHolder.GetComponent<Animation>().CrossFade("arrowHit");
animationHolder.GetComponent<Animation>()
["arrowHit"].speed = 0.8f;
StartCoroutine(GrannyHitByArrow());
}
}
else if (hitByGun)
{
if (!ragdollSpawn)
{
ragdollSpawn = true;
navComponent.speed = 0f;
GrannyHitByGun();
}
}
else if (hitByCar && !ragdollSpawn)
{
ragdollSpawn = true;
navComponent.speed = 0f;
base.gameObject.tag = "Untagged";
GrannyHitByCar();
}
}
if (navComponent.velocity != Vector3.zero)
{
if (!grannyLookUnderBed && !playerGetCaught && !hitByArrow
&& !hitByGun && !bastuKilled && !hitByCar)
{
stopWalk = false;
GrannyMoving = true;
if (!startWalk)
{
if (!grannyIsFollow)
{
if (!grannySeeDoor && !
grannySeeLockedDoor && !droppingBeartrap)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
animationHolder.GetComponent<Animation>()["Walk"].speed = 0.9f;
navComponent.speed = 1.2f;
}
}
else if (seePlayer)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
animationHolder.GetComponent<Animation>()
["Walk"].speed = grannysAnimSpeed;
navComponent.stoppingDistance = 2f;
}
}
}
}
else if (navComponent.velocity == Vector3.zero && !hitByArrow
&& !hitByGun && !bastuKilled && !hitByCar && !grannyLookUnderBed)
{
startWalk = false;
GrannyMoving = false;
if (!stopWalk)
{
stopWalk = true;
if (!attackingPlayer && !GrannySearch && !huntPlayer)
{
if (grannyHearPlayer)
{
if (navComponent.velocity ==
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Look");
}
}
else if (grannyHearObject)
{
if (navComponent.velocity ==
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Look");
}
}
else if (navComponent.velocity == Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
}
}
}
if ((bool)target && !grannyLookUnderBed && !hitByArrow && !
hitByGun && !bastuKilled && !hitByCar)
{
navComponent.destination = target.position;
if (!seePlayer && !grannyIsFollow && !GrannySearching)
{
if (prisondoorClosed)
{
if (waypointStart && !waypointStop)
{
waypointStart = false;
waypointStop = true;
timer = 0f;
if (target.name ==
"TempNavObjects(Clone)")
{
startTimerSearch = true;
GrannySearching = true;
StartCoroutine(Cleaning());
}
if (target.name == "TempNav(Clone)")
{
startTimerSearch = true;
GrannySearching = true;
}
}
}
else if (distanceWaypoint < 5f)
{
if (waypointStart && !waypointStop)
{
waypointStart = false;
waypointStop = true;
timer = 0f;
if (target.name ==
"TempNavObjects(Clone)")
{
startTimerSearch = true;
GrannySearching = true;
StartCoroutine(Cleaning());
}
if (target.name == "TempNav(Clone)")
{
startTimerSearch = true;
GrannySearching = true;
}
}
}
else if (distanceWaypoint > 3f && !waypointStop)
{
waypointStart = true;
}
}
}
if (waypointStop && !hitByArrow && !hitByGun && !bastuKilled && !
hitByCar && !startTimerSearch && (!grannyHearObject || !grannyHearPlayer))
{
timer += Time.deltaTime;
}
if (timer >= 10f && !grannyLookUnderBed && !hitByArrow && !
hitByGun && !bastuKilled && !hitByCar)
{
waypointStop = false;
waypointStart = true;
timer = 0f;
if (!grannyIsFollow)
{
number = UnityEngine.Random.Range(1, 33);
if (!grannyHearPlayer || !grannyHearObject)
{
NewNav();
}
}
}
if (seePlayer)
{
if (!grannyLookUnderBed && !hitByArrow && !hitByGun && !
bastuKilled && !hitByCar)
{
grannyHearPlayer = false;
grannyHearObject = false;
timerSee = 0f;
safeTimer = 0f;
if (!huntPlayer)
{
huntPlayer = true;
if (!grannyIsFollow)
{
grannyIsFollow = true;
FollowPlayer();
}
}
}
}
else if (playerHaveTeddy)
{
if (PlayerPrefs.GetInt("DiffData") != 4 && !
grannyLookUnderBed && !hitByArrow && !hitByGun && !bastuKilled && !hitByCar)
{
grannyHearPlayer = false;
grannyHearObject = false;
timerSee = 0f;
safeTimer = 0f;
if (!huntPlayer)
{
huntPlayer = true;
if (!grannyIsFollow)
{
grannyIsFollow = true;
FollowPlayer();
}
}
}
}
else if (playerStartCar && PlayerPrefs.GetInt("DiffData") != 4 &&
!grannyLookUnderBed && !hitByArrow && !hitByGun && !bastuKilled && !hitByCar)
{
grannyHearPlayer = false;
grannyHearObject = false;
timerSee = 0f;
safeTimer = 0f;
seePlayer = true;
if (!huntPlayer)
{
huntPlayer = true;
if (!grannyIsFollow)
{
grannyIsFollow = true;
FollowPlayer();
}
}
}
if (grannyIsFollow && !hitByArrow && !hitByGun && !bastuKilled &&
!hitByCar)
{
if (!seePlayer)
{
seePlayerTimer = true;
}
else
{
seePlayerTimer = false;
timerSee = 0f;
safeTimer = 0f;
}
}
if (seePlayerTimer && !hitByArrow && !hitByGun && !bastuKilled &&
!hitByCar)
{
timerSee += Time.deltaTime;
if (timerSee >= 6f)
{
seePlayerTimer = false;
grannyIsFollow = false;
huntPlayer = false;
timerSee = 0f;
safeTimer = 0f;
startTimerSearch = true;
GrannySearching = true;
}
}
if (startTimerSearch && !grannyLookUnderBed && !hitByArrow && !
hitByGun && !bastuKilled && !hitByCar)
{
if (GrannySearching)
{
navComponent.speed = 0f;
if (!GrannySearch && navComponent.velocity ==
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Look");
}
}
timerSearch += Time.deltaTime;
if (timerSearch >= 8f)
{
if (navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
animationHolder.GetComponent<Animation>()
["Walk"].speed = 0.9f;
grannyHearPlayer = false;
grannyHearObject = false;
if (!grannyIsFollow)
{
startTimerSearch = false;
GrannySearching = false;
GrannySearch = false;
timerSearch = 0f;
if (!grannySeeDoor && !grannySeeLockedDoor)
{
navComponent.speed = 1.2f;
}
number = UnityEngine.Random.Range(1, 33);
if (!grannyHearPlayer || !grannyHearObject)
{
NewNav();
if (PlayerPrefs.GetInt("DiffData") != 4)
{
StartCoroutine(DropBearTrap());
}
if (playerInPrison && prisondoorClosed)
{
((GrannySounds)grannySounds.GetComponent(typeof(GrannySounds))).grannySkrattar();
}
else
{
((GrannySounds)grannySounds.GetComponent(typeof(GrannySounds))).startGrannySound();
}
}
}
}
}
if (PlayerPrefs.GetInt("DiffData") != 4)
{
Vector3 direction =
doorRay.transform.TransformDirection(Vector3.forward);
Vector3 vector =
doorRay.transform.TransformDirection(Vector3.down);
if (Physics.Raycast(doorRay.transform.position, direction,
out hitInfo, 3f))
{
if (!hitByArrow && !hitByGun && !bastuKilled && !
hitByCar)
{
Debug.DrawRay(doorRay.transform.position,
base.transform.forward, Color.green);
if (hitInfo.collider.gameObject.tag ==
"innerdoorClosed")
{
grannySeeDoor = true;
if (!seePlayer)
{
if (playerHaveTeddy)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
else if (playerStartCar)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
else
{
navComponent.speed = 0f;
}
}
seeClosedDoorTimer += Time.deltaTime;
if (navComponent.velocity ==
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
if (seeClosedDoorTimer >= 2f)
{
hitInfo.collider.gameObject.GetComponent<Animation>().Play("InnerdoorOpen_1");
if (!grannyIsFollow)
{
navComponent.speed = 1.2f;
if (navComponent.velocity !=
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
animationHolder.GetComponent<Animation>()["Walk"].speed = 0.9f;
}
else
{
navComponent.speed =
grannysVarSpeed;
if (navComponent.velocity !=
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
animationHolder.GetComponent<Animation>()["Walk"].speed = grannysAnimSpeed;
}
seeClosedDoorTimer = 0f;
}
}
else if (hitInfo.collider.gameObject.tag ==
"innerdoorLocked")
{
if (!stopSeeLockedDoor)
{
grannySeeLockedDoor = true;
seeClosedDoorTimer +=
Time.deltaTime;
if (grannySeeLockedDoor && !
seePlayer)
{
if (playerHaveTeddy)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
else if (playerStartCar)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
else
{
navComponent.speed = 0f;
}
}
if (navComponent.velocity ==
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
navComponent.speed = 0f;
}
if (seeClosedDoorTimer <= 2f)
{
hitInfo.collider.gameObject.GetComponent<Animation>().Play("InnerdoorLocked");
}
if (seeClosedDoorTimer >= 4f)
{
hitInfo.collider.gameObject.GetComponent<Animation>().Play("InnerdoorOpen");
if (!grannyIsFollow)
{
navComponent.speed =
1.2f;
if
(navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
animationHolder.GetComponent<Animation>()["Walk"].speed = 0.9f;
}
else
{
navComponent.speed =
grannysVarSpeed;
if
(navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
animationHolder.GetComponent<Animation>()["Walk"].speed = grannysAnimSpeed;
}
if (grannySeeLockedDoor &&
seeClosedDoorTimer >= 10f)
{
grannySeeLockedDoor =
false;
stopSeeLockedDoor =
true;
seeClosedDoorTimer = 0f;
grannyHearPlayer =
false;
grannyHearObject =
false;
number =
UnityEngine.Random.Range(1, 33);
NewNav();
}
}
}
}
else if (hitInfo.collider.gameObject.tag ==
"bastudoorLocked")
{
if (!stopSeeLockedDoor)
{
grannySeeLockedDoor = true;
seeClosedDoorTimer +=
Time.deltaTime;
if (grannySeeLockedDoor && !
seePlayer)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
navComponent.speed = 0f;
}
if (navComponent.velocity ==
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
if (seeClosedDoorTimer >= 4f)
{
if (!grannyIsFollow)
{
navComponent.speed =
1.2f;
if
(navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
animationHolder.GetComponent<Animation>()["Walk"].speed = 0.9f;
}
else
{
navComponent.speed =
grannysVarSpeed;
if
(navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
animationHolder.GetComponent<Animation>()["Walk"].speed = grannysAnimSpeed;
}
if (grannySeeLockedDoor &&
seeClosedDoorTimer >= 10f)
{
grannySeeLockedDoor =
false;
stopSeeLockedDoor =
false;
seeClosedDoorTimer = 0f;
grannyHearPlayer =
false;
grannyHearObject =
false;
number =
UnityEngine.Random.Range(1, 33);
NewNav();
}
}
}
}
else if (hitInfo.collider.gameObject.tag ==
"smalldoorClosed")
{
grannySeeDoor = true;
if (!seePlayer)
{
if (playerHaveTeddy)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
else if (playerStartCar)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
else
{
navComponent.speed = 0f;
}
}
seeClosedDoorTimer += Time.deltaTime;
if (navComponent.velocity ==
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
if (seeClosedDoorTimer >= 2f)
{
hitInfo.collider.gameObject.GetComponent<Animation>().Play("SmallDoorOpen");
if (navComponent.velocity !=
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
if (!grannyIsFollow)
{
navComponent.speed = 1.2f;
if (navComponent.velocity !=
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
animationHolder.GetComponent<Animation>()["Walk"].speed = 0.9f;
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
}
else
{
navComponent.speed =
grannysVarSpeed;
if (navComponent.velocity !=
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
animationHolder.GetComponent<Animation>()["Walk"].speed = grannysAnimSpeed;
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
}
seeClosedDoorTimer = 0f;
}
}
else if (hitInfo.collider.gameObject.tag ==
"garde1Closed")
{
grannySeeDoor = true;
if (grannyIsFollow)
{
if (!seePlayer)
{
if (playerHiding)
{
navComponent.speed = 0f;
seeClosedDoorTimer +=
Time.deltaTime;
if
(navComponent.velocity == Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
if (seeClosedDoorTimer
>= 2f)
{
hitInfo.collider.gameObject.GetComponent<Animation>().Play("Garde1Open");
if
(navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
if (!
grannyIsFollow)
{
navComponent.speed = 1.2f;
if
(navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
animationHolder.GetComponent<Animation>()["Walk"].speed = 0.9f;
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
}
else
{
navComponent.speed = grannysVarSpeed;
if
(navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
animationHolder.GetComponent<Animation>()["Walk"].speed = grannysAnimSpeed;
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
}
seeClosedDoorTimer
= 0f;
}
}
seePlayerTimer = true;
}
else
{
seePlayerTimer = false;
timerSee = 0f;
safeTimer = 0f;
}
}
}
else if (hitInfo.collider.gameObject.tag ==
"Untagged")
{
grannySeeDoor = false;
grannySeeLockedDoor = false;
stopSeeLockedDoor = false;
if (navComponent.velocity !=
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
}
}
}
else
{
grannySeeDoor = false;
grannySeeLockedDoor = false;
stopSeeLockedDoor = false;
if (!hitByArrow && !hitByGun && !bastuKilled && !
hitByCar && navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
}
}
Vector3 vector2 = new Vector3(0f, -1f, 0f);
if (Physics.Raycast(checkGround.transform.position, vector2, out
hitInfo, 5f))
{
Debug.DrawRay(checkGround.transform.position, vector2,
Color.yellow);
if (hitInfo.collider.gameObject.name == "StairColliderC")
{
if (!seeStairs)
{
seeStairs = true;
attackDistance = 4.5f;
}
}
else if (hitInfo.collider.gameObject.name == "Golv" &&
seeStairs)
{
seeStairs = false;
attackDistance = 4f;
((GrannyFootstep)animationHolder.GetComponent(typeof(GrannyFootstep))).walkGrus =
false;
}
if (hitInfo.collider.gameObject.tag == "grus")
{
((GrannyFootstep)animationHolder.GetComponent(typeof(GrannyFootstep))).walkGrus =
true;
}
if (hitInfo.collider.gameObject.tag == "golv")
{
((GrannyFootstep)animationHolder.GetComponent(typeof(GrannyFootstep))).walkGrus =
false;
}
}
}
if (distance < attackDistance && seePlayer && !grannyLookUnderBed && !
playerHidingInCoffin && !playerHidingInCoffinBackyard && !playerHidingInCar && !
hitByArrow && !hitByGun && !bastuKilled && !hitByCar && !playerInHole && !
playerGetCaught)
{
playerGetCaught = true;
attackingPlayer = true;
StartCoroutine(Playercaught());
base.transform.LookAt(playerPos);
}
if (!playerGetCaught && !hitByArrow && !hitByGun && !bastuKilled && !
hitByCar)
{
if (distanceWaypoint < 4f && playerHidingUnderBed &&
grannyIsFollow)
{
if (!grannyLookUnderBed && navComponent.velocity !=
Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
navComponent.speed = 0f;
FacePlayerBed();
if (!grannyLookUnderBed)
{
timerBed += Time.deltaTime;
}
if (timerBed >= 3f && playerHidingUnderBed)
{
optionButton.SetActive(false);
animationHolder.GetComponent<Animation>().CrossFade("lookBed");
grannyLookUnderBed = true;
timerBed = 0f;
safeTimer = 0f;
allBedButtons.SetActive(false);
if (hidingUnderBed1)
{
((bedEyes)bedCam1.GetComponent(typeof(bedEyes))).lookAtGranny = true;
if (!soundPlaying)
{
soundPlaying = true;
((soundEffectsBeds)soundHolder1.GetComponent(typeof(soundEffectsBeds))).playerCaugh
t();
}
}
if (hidingUnderBed2)
{
((bedEyes2)bedCam2.GetComponent(typeof(bedEyes2))).lookAtGranny = true;
if (!soundPlaying)
{
soundPlaying = true;
((soundEffectsBeds)soundHolder2.GetComponent(typeof(soundEffectsBeds))).playerCaugh
t();
}
}
if (hidingUnderBed3)
{
((bedEyes3)bedCam3.GetComponent(typeof(bedEyes3))).lookAtGranny = true;
if (!soundPlaying)
{
soundPlaying = true;
((soundEffectsBeds)soundHolder3.GetComponent(typeof(soundEffectsBeds))).playerCaugh
t();
}
}
StartCoroutine(((playerCaughtUnderBed)gameController.GetComponent(typeof(playerCaug
htUnderBed))).EndDayUnderBed());
soundPlaying = false;
}
}
else if (distanceWaypoint < 4f && playerHidingInCoffin &&
grannyIsFollow)
{
navComponent.speed = 0f;
FacePlayerBed();
if (navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
if (!grannyLookUnderBed)
{
timerBed += Time.deltaTime;
}
if (timerBed >= 3f && playerHidingInCoffin)
{
optionButton.SetActive(false);
timerBed = 0f;
safeTimer = 0f;
allBedButtons.SetActive(false);
StartCoroutine(Playercaught());
}
}
else if (distanceWaypoint < 4f && playerHidingInCoffinBackyard &&
grannyIsFollow)
{
navComponent.speed = 0f;
FacePlayerBed();
if (navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
if (!grannyLookUnderBed)
{
timerBed += Time.deltaTime;
}
if (timerBed >= 3f && playerHidingInCoffinBackyard)
{
optionButton.SetActive(false);
timerBed = 0f;
safeTimer = 0f;
allBedButtons.SetActive(false);
StartCoroutine(Playercaught());
}
}
else if (distanceWaypoint < 4f && playerHidingInCar &&
grannyIsFollow && grannyStandBesideCar)
{
navComponent.speed = 0f;
FacePlayerBed();
if (navComponent.velocity != Vector3.zero)
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
if (!grannyLookUnderBed)
{
timerBed += Time.deltaTime;
}
if (timerBed >= 3f && playerHidingInCar)
{
optionButton.SetActive(false);
timerBed = 0f;
safeTimer = 0f;
allBedButtons.SetActive(false);
startCarButton.SetActive(false);
forwardButton.SetActive(false);
reverseButton.SetActive(false);
StartCoroutine(Playercaught());
}
}
else if (!playerHidingUnderBed && !playerHidingInCoffin && !
playerHidingInCoffinBackyard && !playerHidingInCar && grannyIsFollow)
{
FollowPlayer();
}
if (grannyHearPlayer && !seePlayer && !grannyIsFollow)
{
if ((bool)GameObject.Find("TempNav(Clone)Old"))
{
target = GameObject.Find("TempNav(Clone)").transform;
}
else
{
target = GameObject.Find("TempNav(Clone)").transform;
}
if (!grannySeeDoor && !grannySeeLockedDoor)
{
navComponent.speed = grannysVarSpeed;
}
animationHolder.GetComponent<Animation>()["Walk"].speed =
grannysAnimSpeed;
grannyHearObject = false;
droppingBeartrap = false;
}
if (grannyHearObject && !seePlayer && !grannyIsFollow)
{
if ((bool)GameObject.Find("TempNavObjects(Clone)Old"))
{
if ((bool)GameObject.Find("TempNavObjects(Clone)"))
{
target =
GameObject.Find("TempNavObjects(Clone)").transform;
}
else
{
target = nav1;
}
}
else
{
target =
GameObject.Find("TempNavObjects(Clone)").transform;
}
if (!grannySeeDoor && !grannySeeLockedDoor)
{
navComponent.speed = grannysVarSpeed;
}
animationHolder.GetComponent<Animation>()["Walk"].speed =
grannysAnimSpeed;
grannyHearPlayer = false;
droppingBeartrap = false;
if (!resetSafeTimer)
{
resetSafeTimer = true;
safeTimer = 0f;
}
}
if (playerHidingUnderBed && seePlayer && grannyIsFollow)
{
if (hidingUnderBed1)
{
target = bedtargetTemp1;
}
if (hidingUnderBed2)
{
target = bedtargetTemp2;
}
if (hidingUnderBed3)
{
target = bedtargetTemp3;
}
seePlayer = false;
navComponent.stoppingDistance = 2f;
droppingBeartrap = false;
}
else if (playerHidingInCoffin && seePlayer && grannyIsFollow)
{
target = coffintargetTemp4;
}
else if (playerHidingInCoffinBackyard && seePlayer &&
grannyIsFollow)
{
target = coffintargetTempBY;
}
else if (playerHidingInCar && seePlayer && grannyIsFollow)
{
target = cartargetTemp;
}
GrannyDecisions();
}
if (playerNearGranny && !playerGetCaught && !playerHiding)
{
Vector3 vector3 = playerPos.position - base.transform.position;
float maxRadiansDelta = speed * Time.deltaTime;
Vector3 forward = Vector3.RotateTowards(base.transform.forward,
vector3, maxRadiansDelta, 0f);
base.transform.rotation = Quaternion.LookRotation(forward);
}
if (grannyInBastu && bastuswitchOn && bastuBomNere)
{
bastuTimer -= Time.deltaTime;
bastuDoorTimer -= Time.deltaTime;
if (bastuTimer <= 0f)
{
grannyInBastu = false;
bastuKilled = true;
StartCoroutine(GrannyHitByArrow());
}
if (!bastuTimeOff && bastuDoorTimer <= 0f)
{
bastuTimeOff = true;
bastuDoor.gameObject.tag = "innerdoorLocked";
bastuDoorCarv.carving = !base.enabled;
}
}
if (grannyInBastu && !bastuswitchOn && bastuBomNere)
{
if (!bastuTimeOff)
{
bastuDoorTimer -= Time.deltaTime;
if (bastuDoorTimer <= 0f)
{
bastuTimeOff = true;
bastuDoor.gameObject.tag = "innerdoorLocked";
bastuDoorCarv.carving = !base.enabled;
StartbastuSafeTimer = true;
}
}
if (StartbastuSafeTimer)
{
bastuSafeTimer += Time.deltaTime;
if (bastuSafeTimer >= 30f)
{
StartbastuSafeTimer = false;
bastuDoor.gameObject.GetComponent<Animation>().Play("InnerdoorOpen");
}
}
}
if (grannyInBastu && !bastuswitchOn && !bastuBomNere)
{
bastuDoorTimer = 20f;
}
}
((GrannyGoneText)grannyGoneEasyText1.GetComponent(typeof(GrannyGoneText))).textOnOf
f = true;
}
else if (PlayerPrefs.GetInt("DiffData") == 2)
{
((GrannyGoneText)grannyGoneHardText1.GetComponent(typeof(GrannyGoneText))).textOnOf
f = true;
}
else if (PlayerPrefs.GetInt("DiffData") == 3)
{
((GrannyGoneText)grannyGoneExtremeText1.GetComponent(typeof(GrannyGoneText))).textO
nOff = true;
}
}
}
((GrannyGoneText)grannyGoneNormalText1.GetComponent(typeof(GrannyGoneText))).textOn
Off = true;
}
else if (PlayerPrefs.GetInt("DiffData") == 1)
{
((GrannyGoneText)grannyGoneEasyText1.GetComponent(typeof(GrannyGoneText))).textOnOf
f = true;
}
else if (PlayerPrefs.GetInt("DiffData") == 2)
{
((GrannyGoneText)grannyGoneHardText1.GetComponent(typeof(GrannyGoneText))).textOnOf
f = true;
}
else if (PlayerPrefs.GetInt("DiffData") == 3)
{
((GrannyGoneText)grannyGoneExtremeText1.GetComponent(typeof(GrannyGoneText))).textO
nOff = true;
}
}
}
((GrannyGoneText)grannyGoneNormalShotText.GetComponent(typeof(GrannyGoneText))).tex
tOnOff = true;
}
else if (PlayerPrefs.GetInt("DiffData") == 1)
{
((GrannyGoneText)grannyGoneEasyShotText.GetComponent(typeof(GrannyGoneText))).textO
nOff = true;
}
else if (PlayerPrefs.GetInt("DiffData") == 2)
{
((GrannyGoneText)grannyGoneHardShotText.GetComponent(typeof(GrannyGoneText))).textO
nOff = true;
}
else if (PlayerPrefs.GetInt("DiffData") == 3)
{
((GrannyGoneText)grannyGoneExtremeShotText.GetComponent(typeof(GrannyGoneText))).te
xtOnOff = true;
}
}
}
animationHolder.GetComponent<Animation>().CrossFade("Walk");
}
else
{
animationHolder.GetComponent<Animation>().CrossFade("idle");
}
}
}
base.transform.rotation = Quaternion.LookRotation(forw);
}
public virtual IEnumerator Playercaught()
{
if (hitByArrow || hitByGun || bastuKilled || hitByCar || playerInHole)
yield break;
if (playerCaughtLastTime)
{
if (!playerHidingUnderBed)
{
if (playerHidingInCoffin)
{
player.transform.position = PlayerCoffinPos.position;
Player.SetActive(true);
coffinHead1.SetActive(false);
coffinLock.transform.localEulerAngles = new Vector3(-
153.846f, 0f, 0f);
navComponent.speed = 0f;
if (!dontHitPlayer)
{
((playerCrawl)playerHukaKnapp.GetComponent(typeof(playerCrawl))).standUp();
playerHukaKnappParent.SetActive(false);
animationHolder.GetComponent<Animation>().CrossFade("Hit");
((playerCaught)player.GetComponent(typeof(playerCaught))).startFOV = true;
((playerCaught)player.GetComponent(typeof(playerCaught))).grannyTakePlayer =
true;
((playerInBeartrap)gameController.GetComponent(typeof(playerInBeartrap))).playerHit
();
GrannyGonnaSmack = false;
}
}
else if (playerHidingInCoffinBackyard)
{
player.transform.position =
PlayerCoffinBYPos.position;
Player.SetActive(true);
coffinHead2.SetActive(false);
coffinLockBY.transform.localEulerAngles = new
Vector3(165.669f, 0f, 0f);
navComponent.speed = 0f;
if (!dontHitPlayer)
{
playerHukaKnapp.GetComponent<playerCrawl>().standUp();
playerHukaKnappParent.SetActive(false);
animationHolder.GetComponent<Animation>().CrossFade("Hit");
player.GetComponent<playerCaught>().startFOV =
player.GetComponent<playerCaught>().grannyTakePlayer = true;
yield return new WaitForSeconds(0.9f);
((playerInBeartrap)gameController.GetComponent(typeof(playerInBeartrap))).playerHit
();
GrannyGonnaSmack = false;
}
}
else if (playerHidingInCar)
{
player.transform.position = PlayerCarPos.position;
Player.SetActive(true);
carHead.SetActive(false);
navComponent.speed = 0f;
if (!dontHitPlayer)
{
playerHukaKnapp.GetComponent<playerCrawl>().standUp();
playerHukaKnappParent.SetActive(false);
animationHolder.GetComponent<Animation>().CrossFade("Hit");
player.GetComponent<playerCaught>().startFOV =
player.GetComponent<playerCaught>().grannyTakePlayer = true;
playerSounds.GetComponent<soundEffects>().CarOut();
playerStartCar = grannyStandBesideCar =
GrannyGonnaSmack = false;
engineOnSound.SetActive(false);
engineOffSound.SetActive(true);
engineStartSound.SetActive(false);
ObjectHolder.SetActive(true);
gameController.GetComponent<playerInBeartrap>().playerHit();
engineOffSound.SetActive(false);
}
}
else
{
playerNearGranny = GrannyGonnaSmack = false;
navComponent.speed = 0f;
if (!dontHitPlayer)
{
playerHukaKnapp.GetComponent<playerCrawl>().standUp();
playerHukaKnappParent.SetActive(false);
animationHolder.GetComponent<Animation>().CrossFade("Hit");
player.GetComponent<playerCaught>().startFOV =
player.GetComponent<playerCaught>().grannyTakePlayer = true;
if (Spider.activeSelf)
Spider.GetComponent<spiderControll>().grannyCaughtPlayer();
playerSounds.GetComponent<soundEffects>().playerGetHit();
yield return new WaitForSeconds(0.3f);
gameController.GetComponent<playerInBeartrap>().playerHit();
}
}
}
}
else if (!playerHidingUnderBed)
{
playerHukaKnapp.GetComponent<playerCrawl>().standUp();
playerHukaKnappParent.SetActive(false);
if (navComponent.velocity == Vector3.zero)
animationHolder.GetComponent<Animation>().CrossFade("idle");
player.GetComponent<playerCaught>().startFOV =
player.GetComponent<playerCaught>().grannyTakePlayer = true;
GrannyGonnaSmack = false;
}
navComponent.speed = 0f;
}
if (navComponent.velocity != Vector3.zero)
animationHolder.GetComponent<Animation>().CrossFade("Walk");
else animationHolder.GetComponent<Animation>().CrossFade("idle");
navComponent.stoppingDistance = 2f;
animationHolder.GetComponent<Animation>()["Walk"].speed =
grannysAnimSpeed;
target = player;
GrannySearching = startTimerSearch = droppingBeartrap = false;
timerSearch = 0f;
}
}
droppingBeartrap = false;
if (!grannyHearPlayer)
{
UnityEngine.Object.Destroy(GameObject.Find("TempNav(Clone)"));
UnityEngine.Object.Destroy(GameObject.Find("TempNav(Clone)Old"));
}
if (!grannyHearObject)
{
if (GameObject.FindGameObjectsWithTag("noiseobject") != null)
{
NPoints = GameObject.FindGameObjectsWithTag("noiseobject");
for (int i = 0; i < NPoints.Length; i++)
UnityEngine.Object.Destroy(NPoints[i]);
}
StartCoroutine(Cleaning());
}
animationHolder.GetComponent<Animation>()["Walk"].speed = 0.9f;
navComponent.SetDestination(target.position);
navComponent.speed = 1.2f;
waypointWaitTime = false;
safeTimer = 0f;
StartCoroutine(((furnitureControlls)gameController.GetComponent(typeof(furnitureCon
trolls))).cleanUp());
}
}