- Home /
Question by
mwieczorek · Mar 27, 2015 at 04:37 PM ·
camera-movementtransform.positionapplication.loadlevelreset-position
Camera object remember position after scene reload
Hello all,
I have a little problem. I have two scenes: a menu and a sprint. In the sprint my camera follows objects. When scene ends menu is loaded, so the user can launch the sprint again. But when entering sprint another time, the camera is firstly set in the ended position of last sprint. What I have found while debugging is that in Start() method the position is default (set in the unity). But when entering Update() method for the first or second time, the position is changed to 100.
Here is my code:
public class CameraFollower : MonoBehaviour
{
void Start()
{
var startPosition = -1.5f;
MoveCamera(startPosition);
}
void Update()
{
var firstObjectPosition= SprintObjects.GetFirstPosition();
if (firstObjectPosition== 0)
{
return;
}
MoveCamera(firstObjectPosition);
}
private void MoveCamera(float objectPosition)
{
var position = transform.localPosition;
position.x = objectPosition+ 3;
transform.localPosition = position;
}
}
Do you have an idea what can cause this ?
Comment