For my Drive() function I'm calling it through an animation script:
//This script control how all the rover animations animations work when specific keys are pressed
// All animation that are only supposed to play once then hold the final position
animation["idle"].wrapMode = WrapMode.ClampForever;
animation["wheelTurnOut"].wrapMode = WrapMode.ClampForever;
animation["wheelTurnBack"].wrapMode = WrapMode.ClampForever;
animation["landPose"].wrapMode = WrapMode.ClampForever;
//animation["startUp"].wrapMode = WrapMode.ClampForever;
// All animation that are only supposed loop
animation["drive"].wrapMode = WrapMode.Loop;
animation["driveInReverse"].wrapMode = WrapMode.Loop;
animation["rotateRight"].wrapMode = WrapMode.Loop;
animation["rotateLeft"].wrapMode = WrapMode.Loop;
public function Drive ()
{
if (Input.GetKeyDown ("up"))
animation.Blend ("drive", 0.3);
}
function Update ()
{
if (!animation.IsPlaying ("startUp") && !animation.IsPlaying ("armDrillAnimation04"))//|| !animation.IsPlaying("rotateLeft"))
{
if (Input.GetKeyDown ("up")) //("-1"))
animation.Blend ("drive", 0.3);
if (Input.GetKeyDown ("down"))
animation.Blend ("driveInReverse", 0.3);
else if (Input.GetButtonUp ("Vertical"))
animation.CrossFade ("StaticPose");
if (Input.GetButtonDown ("Horizontal")) // tell to wheels to rotate to the spin position
animation.CrossFade ("wheelTurnOut", 0.3);
//tells the rover wheels to rotate right if is is turning right and left if it is rotating left
if (Input.GetKeyDown ("right"))
animation.Blend ("rotateRight", 0.4);
if (Input.GetKeyDown ("left"))
animation.Blend ("rotateLeft", 0.4);
else if (Input.GetButtonUp ("Horizontal"))
animation.CrossFade ("StaticPose");
// If no buttons are being pressed then Wheels will return to their default position
if (Input.GetButtonUp ("Horizontal"))
animation.CrossFade ("wheelTurnBack", 1);
}
}
function OnTriggerEnter ()
{
animation.Play ("armDrillAnimation04");
}
The character (Mars Rover in this case) is controlled with "SampleMoveScript.js" which seems to be my main hangup right now, as I have been able to trigger animations with my new GUI script but cannot link character movement with it. Here is my onGUI() function:
function OnGUI() {
// dPadUp is linked to the "drive" animation here:
if(GUI.RepeatButton (Rect (870,468,43,43), dPadUp, "label") || (Event.current.type == EventType.KeyUp && Event.current.keyCode == KeyCode.Alpha1))
{
rover.animation.Blend ("drive", 0.3);
// this call to move the character is not working:
rover.transform.TransformDirection(Vector3.up);
Debug.Log("Available id: " + GUIUtility.GetControlID(FocusType.Passive));
print("DRIVE!!!");
}
GUI.Button(Rect(790,460,190,190), dPadOutline, style);
//(784,460,200,200)
if(GUI.Button( Rect(794,540,43,43), dPadLeft, "label")) { //subtracted 75 to Ypos
Debug.Log("Clicked the d-pad Left");
}
if(GUI.Button( Rect(932,540,43,43), dPadRight, "label")) {
Debug.Log("Clicked the d-pad Right");
}
if(GUI.Button(Rect(870,468,43,43), dPadUp, "label")) {
Debug.Log("Clicked the d-pad Up");
// Drive();
}
if(GUI.Button(Rect(870,609,43,43), dPadDown, "label")) {
Debug.Log("Clicked the d-pad Down");
}
// Our GUI is laid out for a 1024x768 pixel display. The next line makes sure it rescales nicely to other resolutions.
GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (Screen.height / nativeVerticalResolution, Screen.height / nativeVerticalResolution, 1));
//Draw bottom GUI section (main)
DrawImageBottomAligned( mainImageOffset, mainImage); // main image.
/// Detects keys pressed and prints their keycode
var e : Event = Event.current;
if (e.isKey)
{
Debug.Log("Detected key code: " + e.keyCode);
}
}