void Awake() { Debug.Log("reset"); player = GameObject.Find("Ellen"); coordinates = GameObject.Find("scripts"); key = GameObject.Find("key"); keyHud = GameObject.Find("keyhud"); keyAnimator = keyHud.GetComponent <Animator>(); SpawnCoordinates spawnScript = coordinates.GetComponent <SpawnCoordinates>(); spawn = spawnScript.spawnCoord; rotation = spawnScript.spawnRotation; Character playerScript = player.GetComponent <Character>(); playerScript._controlRotation = new Vector2(0, rotation.y); player.transform.position = new Vector3(spawn.x, spawn.y, spawn.z); player.transform.eulerAngles = new Vector3(0, rotation.y, 0); player.GetComponent <CharacterController>().enabled = true; if (spawnScript.key == true) { KeyCollection keyScript = player.GetComponent <KeyCollection>(); keyScript.keyInventory = true; keyAnimator.SetBool("open", true); Destroy(key); } }
void activateCheckpoint() { SpawnCoordinates spawnScript = coordinates.GetComponent <SpawnCoordinates>(); prompt.SetTrigger("visible"); checkpointText.text = "Checkpoint!"; spawnScript.spawnCoord = checkpoint; spawnScript.spawnRotation = new Vector3(0, this.transform.eulerAngles.y + 90, 0); FindObjectOfType <KeyCollection>().checkpoint(); }
void OnTriggerEnter(Collider col) { if (col.tag == "Player") { KeyCollection keyCollectionScript = player.GetComponent <KeyCollection>(); SpawnCoordinates spawnScript = coordinates.GetComponent <SpawnCoordinates>(); // Sets the spawn coordinates to the checkpoints coordinates. if (spawnScript.spawnCoord != checkpoint) { if (keyCollectionScript.keyInventory == true) { // save key Debug.Log("checkpoint with key " + checkpoint); spawnScript.key = true; activateCheckpoint(); } else if (keyCollectionScript.keyInventory == false) { Debug.Log("checkpoint without key " + checkpoint); // no key activateCheckpoint(); } } // Does nothing if the spawn coordinates are already the checkpoint. else if (spawnScript.spawnCoord == checkpoint) { if (keyCollectionScript.keyInventory == spawnScript.key) { Debug.Log("checkpoint already activated"); } else if (keyCollectionScript.keyInventory != spawnScript.key) { Debug.Log("checkpoint with key " + checkpoint); spawnScript.key = true; activateCheckpoint(); } } } }