Hello everyone. I am having this weird issue. I have a few cameras in my scene and each has the same script that uses this.gameObject to move the camera around (its attached to camera) and when switching to a camera that hasn’t been switch to, everything is good. But when switch back the first camera the script thinks the this.gameObject is the previous camera object.
For example:
User is on camera 1 —> User changes camera and is now camera 2 —> Users goes back to camera 1 but the script thinks that camera 2 that is now disabled is still “this.gameObject” in the script when it’s suppose to be camera 1 that’s enabled and user can not move camera 1 anymore.
I’m not sure how to fix. Been stumped for a few days. Any help will be good. Thanks in advance!
Here is the code for switching cameras:
public void Cameras(string message)
{
cameras[(int)currentCamera].SetActive(false);
currentCamera = (int)float.Parse(message);
cameras[(int)currentCamera].SetActive(true);
}
Here is the code for moving cameras:
void Update(){
if(whichWay == 0)
{
// this.gameObject should change from camera 1 to camera 2 and back again when switching
// but it doesn't...
this.gameObject.transform.position =
Vector3.Slerp(this.gameObject.transform.position,
way[currentNode].transform.position,
camSpeed*Time.deltaTime);
if(Vector3.Distance(this.gameObject.transform.position,
way[currentNode].transform.position) < 0.01f)
{
check = 1;
whichWay = 5;
}
}
else if(whichWay == 1)
{
this.gameObject.transform.position =
Vector3.Slerp(this.gameObject.transform.position,
way[currentNode].transform.position,
camSpeed*Time.deltaTime);
if(Vector3.Distance(this.gameObject.transform.position,
way[currentNode].transform.position ) < 0.01f)
{
check = 1;
whichWay = 5;
}
}
}