void Awake() { buildingUI = GetComponent <BuildingUI>(); buildingRevenue = GetComponent <BuildingRevenue>(); buildingExports = GetComponent <BuildingExports>(); sphereOfInfluence = GetComponent <SphereOfInfluence>(); }
// Most interactions between the follower and other entities happen on OnTriggerEnter, when the follower steps into their sphere of influence. // Depending on the follower's currentState, currentCharisma, and (if already following a leader) the leader's charisma. private void OnTriggerEnter(Collider other) { // If is in player range and not already following the player, // OR if following another entity AND player charisma > current leader charisma, become clickable. if (other.gameObject.CompareTag("Player") && overrideTarget == false) { SphereOfInfluence playerSphere = other.gameObject.GetComponentInParent <SphereOfInfluence>(); if (currentState == State.Idle || (currentState == State.FollowOther && playerSphere.currentCharisma > currentLeader.GetComponentInParent <SphereOfInfluence>().currentCharisma)) { //Debug.Log(this.name + " becomes clickable."); ChangeMaterial(clothes, clickableMaterial); isClickable = true; } if (currentState == State.FollowOther && currentCharisma > playerSphere.currentCharisma) { Debug.Log(this.name + " attack " + other.transform.gameObject.name); SetAttackTarget(other.transform.parent.gameObject.transform); } } // If is in Taker range AND is idle AND Taker charisma is higher than currentCharisma, // OR if following another entity AND Taker charisma is higher than current leader's charisma, start following the new taker. if (overrideTarget == false && (other.gameObject.CompareTag("Taker") || (other.gameObject.CompareTag("Player") && other.GetComponentInParent <PlayerController>().autoCollectFollowers == true))) { if (other.gameObject.GetComponentInParent <SphereOfInfluence>() != null) { SphereOfInfluence otherSphere = other.gameObject.GetComponentInParent <SphereOfInfluence>(); if ((currentState == State.Idle && currentLeader == null && otherSphere.currentCharisma > currentCharisma) || currentLeader != null && currentLeader.GetComponentInParent <SphereOfInfluence>() != null && otherSphere.currentCharisma > currentLeader.GetComponentInParent <SphereOfInfluence>().currentCharisma&& (currentState == State.FollowOther || (currentState == State.FollowPlayer && currentLeader.CompareTag("Player")))) { SetFollowLeader(other.transform.parent.gameObject.transform); } // If is already following a leader AND walks into Taker sphere AND new taker charisma < this.currentCharisma -> Attack the taker. if (currentState == State.FollowPlayer && other.CompareTag("Taker") && otherSphere.currentCharisma < currentCharisma) { Debug.Log(this.name + " attack " + other.transform.gameObject.name); SetAttackTarget(other.transform.parent.gameObject.transform); } } } }