/// <summary> /// Start this instance. /// </summary> private void Start() { // Gather potential sub-entity information and existing cell information _parentEntity = transform.parent.GetComponentInParent <CELL_ENTITY> (); _parentCell = transform.parent.GetComponentInParent <CELL> (); if (_parentEntity != null) { // If the entity is a sub-entity, register with the parent entity _parentEntity.On_Cell_Entity_Generate += Generate; } else { // If the entity is not a sub-entity, register with the cell _parentCell.On_Cell_Generate += Generate; } // Define the audience _audience = new List <NPC> (); // Set the tag for the entity if (isPointOfInterest && this.name != "NPC") { tag = "Point_Of_Interest"; } }
/// <summary> /// Start this instance. /// </summary> private void Start() { _meshRenderer = GetComponent <MeshRenderer> (); _audioSource = GetComponent <AudioSource> (); _cellEntity = GetComponent <CELL_ENTITY> (); if (_cellEntity != null) { _cellEntity.On_Cell_Entity_Generate += delegate { _meshRenderer.enabled = true; _hasBeenInteractedWith = false; }; } _defaultInteractionPrompt = GameObject.FindGameObjectWithTag("UI_Interaction_Prompt").GetComponent <Text> (); }
/// <summary> /// Changes the point of interest. /// </summary> /// <param name="_newPointOfInterest">New point of interest.</param> public void Change_Point_Of_Interest(CELL_ENTITY _newPointOfInterest = null) { // If the point of interest is not passed in if (_newPointOfInterest == null) { _newPointOfInterest = (name.Equals("JOE"))? CELL.allCells [Random.Range(0, CELL.allCells.Count)].randomPointOfInterest : parentCell.randomPointOfInterest; } // Set isIdling to false _isIdling = false; if (_targetPointOfInterest != null) { // Remove the npc from the target point of interest's audience _targetPointOfInterest.audience.Remove(this); } // Set the new point of interest _targetPointOfInterest = _newPointOfInterest; // ************************** // Animate! // ************************** // Set the navmesh agent destination & set has registered to false if (_targetPointOfInterest != null) // && _agent.isOnNavMesh == true) //would this help? { _agent.SetDestination(_targetPointOfInterest.transform.position); // Set the idle bool to true if (_anim.runtimeAnimatorController != null) { _anim.SetFloat("Walking_Speed", 1f); } } _hasRegisteredWithPointOfInterest = false; }
/// <summary> /// Raises the trigger stay event. /// </summary> /// <param name="_c">C.</param> private void OnTriggerStay(Collider _c) { // If the NPC is within a point of interest if (_c.CompareTag("Point_Of_Interest") && !_hasRegisteredWithPointOfInterest) { // Get the attached entity script CELL_ENTITY _entity = _c.GetComponent <CELL_ENTITY> (); // If it is the target point of interest if (_targetPointOfInterest != null && _entity == _targetPointOfInterest) { // Reset the agent destination for a more spread-out collection of NPCs float _newX = (Random.Range(0, 2) > 0)? Random.Range(2.0f, 3.0f) : Random.Range(-3.0f, -2.0f); float _newZ = (Random.Range(0, 2) > 0)? Random.Range(2.0f, 3.0f) : Random.Range(-3.0f, -2.0f); _agent.SetDestination(_targetPointOfInterest.transform.position + new Vector3(_newX, 0, _newZ)); // Specify that the npc has registered _hasRegisteredWithPointOfInterest = true; // Start Idling StartCoroutine(Idle()); } } }