void OnTriggerEnter(Collider other) { if (other.tag == "Player") { Keybearer player = other.gameObject.GetComponent <Keybearer>(); if (player != null) { SaveValues(player); } } }
private void SaveValues(Keybearer player) { PlayerPrefs.SetInt("PlayerKey", player.posessedKey); PlayerPrefs.SetString("Name", CheckpointName); PlayerPrefs.SetInt("CheckPointReached", 1); PlayerPrefs.SetString("CheckPointName", CheckpointName); //CompanionAI[] Companions = FindObjectsOfType<CompanionAI>(); mCompanion = player.GetComponent <PlayerMovement>().myCompanion; //If the player has a companion following him if (mCompanion != null) { //If it is actvely following and within range if ((mCompanion.activeFollow && Vector3.Distance(mCompanion.gameObject.transform.position, gameObject.transform.position) < 20)) { PlayerPrefs.SetString("CompanionPresent", mCompanion.name); } //If the companion is at a dropoff and shouldn't be left behind else if (mCompanion.atDropOff && !mCompanion.LeaveBehind && mCompanion.DropOff != null) { PlayerPrefs.SetString("CompanionPresent", mCompanion.name); PlayerPrefs.SetString("DropOffLocation", mCompanion.DropOff.name); } //If we just tell that companion to spawn at their last location else if (mCompanion.SpawnAtLastLocation) { PlayerPrefs.SetString("CompanionPresent", mCompanion.name); PlayerPrefs.SetFloat("CompanionX", mCompanion.transform.position.x); PlayerPrefs.SetFloat("CompanionY", mCompanion.transform.position.y); PlayerPrefs.SetFloat("CompanionZ", mCompanion.transform.position.z); } } else { PlayerPrefs.DeleteKey("CompanionPresent"); PlayerPrefs.DeleteKey("DropOffLocation"); PlayerPrefs.DeleteKey("CompanionX"); PlayerPrefs.DeleteKey("CompanionY"); PlayerPrefs.DeleteKey("CompanionZ"); } }