// Start is called before the first frame update void Start() { navPoint = destPoints.GetComponentsInChildren <Transform>().ToList(); navPoint.RemoveAt(0); fov = GetComponent <FOVDetection>(); agent.autoBraking = false; }
private void Start() { fov = GetComponent <FOVDetection>(); agent = GetComponent <NavMeshAgent>(); attackRange = 0f; }
private void Awake() { if (instance == null) { instance = this; DontDestroyOnLoad(this); } else { Destroy(this); } }
void Start() { fovDetection = GetComponent <FOVDetection>(); agent = GetComponent <NavMeshAgent>(); animator = GetComponent <Animator>(); if (points.Length == 0) { initialPosition = transform.position; initialRotation = transform.rotation; } else { GotoNextPoint(); } }
// Start is called before the first frame update void Start() { agent = GetComponent <NavMeshAgent>(); prey = PlayerManager.instance.player.gameObject; enemyAttack = GetComponent <EnemyAttack>(); enemyDamage = GetComponent <EnemyDamage>(); animator = GetComponent <Animator>(); fovDetection = GetComponent <FOVDetection>(); alerted = false; canAttack = false; seekingEnemy = true; wanderTimer = Random.Range(3, 7); reactTimer = Random.Range(5, 10); timer = wanderTimer; timer = reactTimer; }
// FixedUpdate is called once per frame void FixedUpdate() { // Walk Animation SetIsWalking(canWalk); if ((!Player.GetInstanceControl().IsInvisible() && FOVDetection.InFOV(transform, Player.GetArmatureTransform(), maxAngle, lookRadius)) || alertedBefore) { AlertEnemy(); // Stopping agent from moving canWalk = false; agent.ResetPath(); // Enemy looks to the player SetIsAiming(true); Vector3 direction = (Player.GetArmatureTransform().position - transform.position).normalized; Quaternion lookRotation = Quaternion.LookRotation(new Vector3(direction.x, direction.y, direction.z)); FaceTarget(lookRotation); gun.SetShootingDirection(direction); if (!wasInFOV) { StopAllCoroutines(); StartCoroutine(shootingBehaviour); } wasInFOV = true; } else if (wasInFOV) { //If the player isn't in the enemy FOV, the enemy continues its path canWalk = true; wasInFOV = false; SetIsAiming(false); SetAgentNewDestination(); StopCoroutine(shootingBehaviour); } if (canWalk && Vector3.Distance(enemyTargetPositions[currentTargetPosition], transform.position) <= stoppingDistanceError && agent.remainingDistance == 0) { canWalk = false; StartCoroutine(WaitOnPosition()); } }
// General Start Method in which the enemy start from IDLE state protected virtual void Start() { player = PlayerStatistics.instance.transform; agent = GetComponent <NavMeshAgent>(); fov = GetComponent <FOVDetection>(); animator = GetComponentInChildren <Animator>(); soundSource = GetComponentsInChildren <AudioSource>(); originPos = transform.position; originRot = transform.rotation; if (!isInitialStatusAcceptable(initialStatus)) { throw new System.Exception("Error: initial status not acceptable for gameobject " + gameObject.name); } if (patrolPath != null && idleType != IdleType.PATROL) { throw new System.Exception("Error: cannot assign a PatrolPath with a IdleType different from PATROL for object: " + gameObject.name); } else if (patrolPath == null && idleType == IdleType.PATROL) { throw new System.Exception("Error: PatrolPath not assigned for object: " + gameObject.name); } if (initialStatus != Status.INACTIVE) { spawn = true; animator.SetTrigger(animVarSpawn); } else { SetEnableColliders(false); // an enemy in INACTIVE status don't have to be collidable } idleTimer = -1; // this will cause a call to newRandomDestination model = transform.GetChild(0); originModelPos = model.localPosition; originModelRot = model.localRotation; ChangeStatus(initialStatus); }