// Update is called once per frame void Update() { Collider[] hits = Physics.OverlapSphere(transform.position, 2); foreach (Collider hit in hits) { if (hit.tag == "Companion" && stats.currentCompanions < stats.maxCompanions) { referenceObject = hit.gameObject; if (hit.gameObject.name == "Health Roo(Clone)") { referenceScript = referenceObject.GetComponent <HealthRooBehaviour>(); if (!(referenceScript.hasMasterGetter())) { referenceScript.OnRescue(); stats.CompanionList[counter] = referenceObject; counter++; stats.currentCompanions += 1; } } else if (hit.gameObject.name == "Speed Roo(Clone)") { referenceScript = referenceObject.GetComponent <SpeedRooBehaviour>(); if (!(referenceScript.hasMasterGetter())) { referenceScript.OnRescue(); stats.CompanionList[counter] = referenceObject; counter++; stats.currentCompanions += 1; } } } } }
void OnTriggerEnter(Collider other) { if (m_Objective.isCompleted) { return; } CompanionBehaviour companion = other.GetComponent <CompanionBehaviour>(); Debug.Log(companion); // test if the other collider contains a PlayerCharacterController, then complete if (companion != null && companion.GetPackLeader().CompareTag("Player")) { m_Objective.CompleteObjective(string.Empty, string.Empty, "Objective complete : " + m_Objective.title); companion.Follow(); if (GetComponentInParent <ObjectiveUnlocker>()) { GetComponentInParent <ObjectiveUnlocker>().ObjectiveCompleted(_index); } // destroy the transform, will remove the compass marker if it has one Destroy(destroyRoot.gameObject); } else if (other.GetComponent <BirdBot>()) { m_Objective.CompleteObjective(string.Empty, string.Empty, "Objective complete : " + m_Objective.title); other.GetComponent <BirdBot>().SetStateToFollow(); if (GetComponentInParent <ObjectiveUnlocker>()) { GetComponentInParent <ObjectiveUnlocker>().ObjectiveCompleted(_index); } // destroy the transform, will remove the compass marker if it has one Destroy(destroyRoot.gameObject); } }