// Use this for initialization void Start() { //Clone player and get the PlayerNew script and record the spawnPoint player = Instantiate(playerPrefab, new Vector3(startPosition.position.x, startPosition.position.y, -1), Quaternion.identity); playerData = player.GetComponent <PlayerNew>(); playerData.setSavePointPos(startPosition.position); allDoors = GameObject.FindGameObjectsWithTag("Door"); allKeys = GameObject.FindGameObjectsWithTag("Key"); keyToBeSaved = new List <GameObject>(); keySaved = new List <GameObject>(); doorToBeSaved = new List <GameObject>(); doorSaved = new List <GameObject>(); sprint.maxValue = playerData.MaxStamina; battery.maxValue = playerData.Battery; }
//Set player hp back to the max, record the position of the save point only if this save point isn't activated private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag == "Player") { PlayerNew player = collision.gameObject.GetComponent <PlayerNew>(); player.setSavePointPos(transform.position); if (!check) { player.hp = player.MaxHP; check = true; } player.SetBattery(recoverBatteryNum); if (crushingWall != null) { crushingWall.SaveWallState(); } GameManager.gm.SaveDoor(); GameManager.gm.SaveKey(); GameManager.gm.ShowSaveText(); } }