Hi guys,
I am encountering a strange phenomena and I hope to seek some experts advices here.
Keeping the long story short, I have three scripts, a ScriptA for GUI and in which a button, where upon pressed on, changed a static variable "ChangeCameraAngle" (as boolean and originally set to FALSE) in ScriptB, and one more ScriptC that will based on the changed "ChangeCameraAngle" and start a Quaternion.Slerp and a Vector3.Slerp on the camera from its initial rotation, say (45, 0, 0), and its initial transform, say (100, 100, 100), respectively. All these scripts are attached to the GameObject 'Camera'.
First, ScriptB is just defining static variables (among others but I am leaving them out here):
static var ChangeCameraAngle : boolean = false;
ScriptA goes like this (leaving out other non-related lines):
function OnGUI () {
if (GUI.Button (Rect (0, 0, 150, 40), "ROTATE CAMERA")) {
ScriptB.ChangeCameraAngle = true;
}
ScriptC goes like this (leaving out other non-related lines):
function Update () {
....
if (ScriptB.ChangeCameraAngle == true) {
var NewRotation = Quaternion.Euler(0, 0, 0);
var NewPosition = Vector3(0, 0, 0);
transform.localRotation = Quaternion.Slerp (transform.localRotation, NewRotation, Time.time * 0.01);
transform.localPosition = Vector3.Slerp (transform.localPosition, NewPosition, Time.time * 0.01);
}
}
The Vector3.Slerp worked as intended, in that the camera moved from (100, 100, 100) to (0, 0, 0) when 'triggered' by "ScriptB.ChangeCameraAngle == true". But not so for the Quaternion.Slerp. The camera's angle jumped straight from (45, 0, 0) to (0, 0, 0), as if time.Time has no effect, despite I tried with a very small value of "time.Time * 0.0000001" too.
Now, the strange phenomena is that, for diagnosis purposes, IF I deliberately add another boolean variable in ScriptA or ScriptC to 'link' to "ScriptB.ChangeCameraAngle", so that I trigger a manual change of "ScriptB.ChangeCameraAngle" via the Inspector during play, the Quaternion.Slerp in ScriptB works according.
The additional "manual trigger" in ScriptA or ScriptC is just simply this:
var ManualTrigger : boolean = false;
function Update () {
....
if (ManualTrigger == true) {
ScriptB.ChangeCameraAngle = true;
}
}
So now I am at a loss, not exactly sure what was wrong with the original scripts. Would some kind souls out there please advise me? Many Thanks!