- Home /
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:
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)
Your answer
Follow this Question
Related Questions
How to create a gui button inside an if statement? 1 Answer
How to control keyboard via GUI button. 1 Answer
Turn off my GUI Box when I click a button. 3 Answers
Making a GUI button appear after pressing another GUI button? C# 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers