I have 2 buttons.
End Turn and End Animation
I want the following to happen:
player clicks the end turn button, camera moves down smoothly (using the coroutine), and the end turn button is set to false and the end animation button is set to true. Upon clicking the end animation button, i want it to be set as false, and the end turn button should turn back on. It’s pretty simple…
BUT, I have a problem.
If I run the game with this function (those lines in comment), it runs as I wanted.
public void detectButtoETnPlusMoveCam () {
applyClickScript.Click = true;
if (changeTurn.playerTurn == 0) {
StartCoroutine( LerpFromTo(mainCam.transform.position, targetPosition, mainCam.transform.rotation, targetRotation, 1f) );
}
if (changeTurn.playerTurn == 1) {
StartCoroutine (LerpFromTo (mainCam.transform.position, targetPosition2, mainCam.transform.rotation, targetRotation2, 1f));
}
//EndTurnB.SetActive (false);
//EndAnimationB.SetActive (true);
}
But if I delete the comments, the coroutine is no longer ran by the game… It pisses me off… Struggling with this for days and still haven’t found a proper fix… Please help me guys.
Yes, I made sure to declare, drag&drop the buttons.
The function is called upon clicking the End Turn Button.
Further things that I wanted to be shown as well…
The function called when End Animation button is clicked
public void detectButtoEAnPlusMoveCam () {
applyClickScript.aClick = true;
if (changeTurn.playerTurn == 0) {
StartCoroutine( LerpFromTo(mainCam.transform.position, targetPosition, mainCam.transform.rotation, targetRotation, 1f) );
}
if (changeTurn.playerTurn == 1) {
StartCoroutine (LerpFromTo (mainCam.transform.position, targetPosition2, mainCam.transform.rotation, targetRotation2, 1f));
}
//EndAnimationB.SetActive (false);
//EndTurnB.SetActive (true);
}
Aand, the mighty IEnumerator
IEnumerator LerpFromTo(Vector3 pos1, Vector3 pos2, Quaternion rot1, Quaternion rot2, float duration) {
for (float t=0f; t<duration; t += Time.deltaTime) {
mainCam.transform.position = Vector3.Lerp(pos1, pos2, t / duration);
mainCam.transform.rotation = Quaternion.Slerp(rot1, rot2, t / duration);
yield return 0;
}
mainCam.transform.position = pos2;
mainCam.transform.rotation = rot2;
}
I talked about this with one of my friends and he told me something about every single gameobject/script running on a different ‘thread’. Is is correct? What should I do?