GUI controlled movement

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:


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)
more ▼

asked Jan 24, 2011 at 10:02 PM

LANDO gravatar image

54 33 28 32

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments



asked: Jan 24, 2011 at 10:02 PM

Seen: 1852 times

Last Updated: Jan 24, 2011 at 10:02 PM