I'm missing a method to link up character control with animations which are triggered through my GUI.
I found a helpful script which triggers animation through GUI buttons here:
http://answers.unity3d.com/questions/18382/i-need-help-assigning-animation-clips-to-gui-buttons
var model : GameObject;
function OnGUI () {
//background box
GUI.Box (Rect (10,130,100,90), "Controls");
//Make first button
if (GUI.Button (Rect(20,160,80,20), "Arm")){
model.animation.Play("raise arms", PlayMode.StopAll);
}
//Make second button
if (GUI.Button (Rect(20,190,80,20), "Neck")){
model.animation.Play("raise neck", PlayMode.StopAll);
}
}
I'm attempting to get this to work with something similar to the "SampleMoveScript.js"
var speed = 3.0;
var rotatationSpeed = 200.0;
private var curSpeed = 0.0;
function Update ()
{
if (!animation.IsPlaying ("startUp") && !animation.IsPlaying ("armDrillAnimation04"))
{
// Rotate around y-axis
var newRotation = Input.GetAxis("Horizontal") * rotatationSpeed;
transform.Rotate(0, newRotation * Time.deltaTime, 0);
// Calculate speed
var newSpeed = Input.GetAxis("Vertical") * speed;
if (Input.GetKey("left shift"))
newSpeed *= 1.5;
// Move the controller
var controller : CharacterController = GetComponent (CharacterController);
var forward = transform.TransformDirection(Vector3.forward);
controller.SimpleMove(forward * newSpeed);
// Update the speed in the Animation script
SendMessage("SetCurrentSpeed", newSpeed, SendMessageOptions.DontRequireReceiver);
SendMessage("SetCurrentLean", Input.GetAxis("Horizontal"), SendMessageOptions.DontRequireReceiver);
}
}
@script RequireComponent (CharacterController)
asked
Jan 24 '11 at 10:02 PM
LANDO
54
●
10
●
13
●
18