hey folks,
i got this little problem with some buttons of mine.
What i want is this:
when i push a button on my screen it has to send a message to another object->script that tells him to walk forward
but it sends the message when you release the button.
it has to be when you hold the button down that it has to send the message.
this is the short script (the whole script is like 500 lines)
var camera1object : GameObject;
var camera2object : GameObject;
var ArrowSize = Vector2(20,20);
var upImage : Texture2D;
function OnGUI ()
{
if (GUI.Button(Rect(0,0,ArrowSize.x,ArrowSize.y),upImage))InputForward();
}
function InputForward()
{
if (camera1object.active)
{
camera1object.SendMessage ("walkForward", 1);
}
if (camera2object.active)
{
camera2object.SendMessage ("walkForward", 1);
}
}
This script is the standard FPSWalker with some addons.
var speed = 0.0;
var loopspeed = 6.0;
var sprintspeed = 9.0;
var jumpSpeed = 8.0;
var gravity = 20.0;
var turnSpeed = 0.0;
private var moveDirection = Vector3.zero;
private var grounded : boolean = false;
function Update ()
{
print(speed);
}
function FixedUpdate() {
if (grounded) {
// We are grounded, so recalculate movedirection directly from axes
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
speed = loopspeed;
if (Input.GetButton ("Jump")) {
moveDirection.y = jumpSpeed;
}
if (Input.GetButton ("Sprint")) {
speed = sprintspeed;
}
}
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
var flags = controller.Move(moveDirection * Time.deltaTime);
grounded = (flags CollisionFlags.CollidedBelow) != 0;
// Check to see if the right mouse button is pressed
if (Input.GetMouseButton(1))
{
// Get the difference in horizontal mouse movement
x = Input.GetAxis("Mouse X") * turnSpeed;
}
// rotate the character based on the x value
transform.Rotate(0, x, 0);
//print (transform.rotation.eulerAngles);
}
function walkForward(val:float)
{
//transform.Rotate(0, 1 * turnSpeed, 0);
Debug.Log("My finger is on the button");
}
if you need some more info ask me.
Thnx!