void Update() { if (newCharacter) { followTarget = characterSelector.GetCharacterObject(); } if (characterSelector != null) { if (characterSelector.GetCharacterActive()) //checks if the character is active { targetPos = new Vector3(followTarget.transform.position.x, followTarget.transform.position.y, transform.position.z); //using the z position of the camera } else { if (playerStartPoint != null) { targetPos = new Vector3(playerStartPoint.GetStartPosition().x, playerStartPoint.GetStartPosition().y, -10); //sets the camera's default position to the position of the player start point game object to prevent camera drag on character spawn } else { targetPos = new Vector3(0, 0, -10); //if there is no player start point present, default the camera to these values } } } transform.position = Vector3.Lerp(transform.position, targetPos, moveSpeed * Time.deltaTime); //current position, new position (target position), amount of movement per frame - Using Time.deltaTime to adjust to computer framerates }
void Start() { playerHealthBarManager = FindObjectOfType <PlayerHealthBarManager>(); //gets a reference to the PlayerHealthBarManager script playerStartPoint = FindObjectOfType <PlayerStartPoint>(); if (playerStartPoint != null) //if there is a player start point present, change the player's starting position to its values { playerSpawnPosition = playerStartPoint.GetStartPosition(); //sets the player's spawn position to the position of the player start point game object to prevent camera drag on character spawn } if (!UIExists) //if the UI doesn't exist in the current scene, don't destroy the UI between scene swapping { UIExists = true; DontDestroyOnLoad(transform.gameObject); } else { Destroy(gameObject); } }