transform.position not applying to my camera.
I've got my MainCamera set to (0,7,12) and, when the scene starts, I want to move it to (0,7,-7).
I don't want to use code in Update() as it is only a one time transition, so I'm using a CoRoutine called at Start().
To do so, I've got this script:
public class CameraControl : MonoBehaviour {
void Start () {
StartCoroutine (movInicial ());
}
IEnumerator movInicial () {
bool inPos = false;
while ( !inPos ) {
float movZ = transform.position.z - 1;
transform.position = new Vector3 (transform.position.x, transform.position.y, movZ);
Debug.Log (movZ);
if (transform.position.z <= -7){
inPos = true;
}
yield return null;
}
}
}
My problem is, when I test it, Debug.Log (movZ);
is constantly returning the value of 11.
I've tested lots of things, don't tell me try this or that code much different from mine please :D
I just need an explanation on why transform.position = new Vector3 (x,y,z)
does not change my camera's position.
Thank you,
A noob ^^
Please check if you added the script to the camera GameObject.
Answer by Xesk · Dec 27, 2017 at 02:48 PM
I've found the error,
I had other code in Update() that executed parallel with my CoRo, and it was in conflict with this code.
So CoRo updated the position, and then the Update() placed back the camera at the starting position.