- Home /
How can camera Forward Or How to change position of camera?
i m working on 3D game,i take 4 home in level1,and take 4 home in level2, in level1 when home1 empty space fillup complete. what can i do when complete fill up empty space home 1 then camera should be going on home 2?? what can i do for this..?? or how to change position of camera??
Code:
public Camera cams;
void fixedupdate()
{
gameover();
}
void gameover()
{
//some code here
//camera position change code
Vector3 positions = cams.transform.position + new Vector3(-12, 0, 0);
Debug.Log("position" + positions);
}
Referance:
//camera position change but camera not move
Answer by Doctor_ED · May 18, 2019 at 11:09 AM
In the :
void gameover()
{
//some code here
//camera position change code
Vector3 positions = cams.transform.position + new Vector3(-12, 0, 0);
Debug.Log("position" + positions);
}
you are only calculating new position for the camera, and not applying it to camera gameObject. To fix it :
void gameover()
{
//some code here
//camera position change code
Vector3 positions = cams.transform.position + new Vector3(-12, 0, 0);
cams.transform.position = positions;
Debug.Log("position" + positions);
}
public Camera cams1;
private Vector3 secondhome= new Vector3(5.6f,19f,2.7f);
private Vector3 thirdhome = new Vector3(-10,19,2.7f);
private Vector3 fourthhome = new Vector3(-22,19,2.7f);
exactly but problem was there i have only one camera
what i m trying to do now: cams1.transform.position = secondhome;
//when first complete then second
firstcomplete then second come but third and fourth home not come when second complete??
It's a bit messy. I'm not sure if I understand what you are trying to do, but I assume that you just want to move camera to next home, after fininshing previous one. If so :
[SerializeField]
private Camera cam;
[SerializeField]
private Vector3[] homesPositions =
{
new Vector3(5.6f,19f,2.7f),
new Vector3(-10,19,2.7f),
new Vector3(-22,19,2.7f)
};
private int nextHomeIndex = 0;
private void NextHome()
{
if (nextHomeIndex < homesPositions.Length)
{
cam.transform.position = homesPositions[nextHomeIndex];
nextHomeIndex++;
} else
{
//You are already in the last home
}
}
Call the NextHome() when player finishes given home.
home1 bydefault active when player finish home1 then active home2(home 2 complete) and then active home 3(home 3 complete) and then active home4(home4 complete) then how can i move the player going next level???how can i manage my home??
private Vector3 firsthome = new Vector3(17.6f,19,2.7f);
private Vector3 secondhome= new Vector3(5.6f,19f,2.7f);
private Vector3 thirdhome = new Vector3(-10,19,2.7f);
private Vector3 fourthhome = new Vector3(-22,19,2.7f);
public GameObject home1;
public GameObject home2;
public GameObject home3;
public GameObject home4;
if (complete.Length == 0) // (8==8)
{
//when first homecomplete then second homeactive
cam.transform.position = secondhome;
//home1 complete then home1 inactive
home1.SetActive(false);
//home1 complete then home2 active
home2.SetActive(true);
$$anonymous$$yGameOver();
Debug.Log("inside the completecall");
}
how to manage my third and fourth home???