-2
\$\begingroup\$

I'm working on 3D game, where the player needs to complete 4 play fields called "homes" in level 1, then progress to level 2 which has 4 homes of its own.

In level 1, when the player completes the first home, how can I move the camera to the second home?

Referance:

Scene view of 4 homes in level 1 Gameover script on camera:

void fixedupdate()
{
 gameover();
}
void gameover()
{
     //some code here
    //camera position change but not move when my game over
    Vector3 positions = cams.transform.position + new Vector3(-12, 0, 0);
}
\$\endgroup\$
  • 1
    \$\begingroup\$ Vector3 positions is just a temporary variable that Unity doesn't care about. Did you mean to assign this value to cams.transform.position to move the camera? \$\endgroup\$ – DMGregory May 18 at 12:38
  • \$\begingroup\$ @DMGregory thanks for given suggestion solved problem \$\endgroup\$ – rahul patil May 20 at 8:31
1
\$\begingroup\$
void gameover()
{
    Vector3 positions = cams.transform.position + new Vector3(-12, 0, 0);
}

This code creates a temporary variable called positions and assigns it a value 12 units to the left of the camera's position. It then does nothing whatsoever with that variable, and exits.

If you want to move the camera, then you can assign your new shifted position value to the camera's transform.position property:

void gameover()
{
    // Compute the new desired position for the camera in a temporary variable.
    Vector3 newPosition = cams.transform.position + new Vector3(-12, 0, 0);
    // Assign that position to the camera's transform to actually move it.
    cams.transform.position = newPosition;
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.