- Home /
Question by
shasha2001 · Mar 12, 2015 at 02:56 PM ·
uieventsystemkeyboardunity 4.6input.getaxis
how to simulate keyboard left right keys to touch button in unity 4.6 ?
torqueDir = Input.GetAxis ("Horizontal");
if (torqueDir != 0) {
rigidbody2D.AddTorque (3 * Mathf.PI * torqueDir, ForceMode2D.Force);
} else {
rigidbody2D.AddTorque (0);
}
slope = transform.localEulerAngles.z;
//convert the slope values greater than 180 to a negative value so as to add motor speed
//based on the slope angle
if (slope >= 180)
slope = slope - 360;
// dir = Input.GetAxis ("Horizontal");
Debug.Log (dir);
if (dir != 0)
//add speed accordingly
motorBack.motorSpeed = Mathf.Clamp (motorBack.motorSpeed - (dir * accelerationRate - gravity * Mathf.Sin ((slope * Mathf.PI) / 180) * 80) * Time.deltaTime, maxFwdSpeed, maxBwdSpeed);
//if no input and car is moving forward or no input and car is stagnant and is on an inclined plane with negative slope
if ((dir == 0 && motorBack.motorSpeed < 0) || (dir == 0 && motorBack.motorSpeed == 0 && slope < 0)) {
//decelerate the car while adding the speed if the car is on an inclined plane
motorBack.motorSpeed = Mathf.Clamp (motorBack.motorSpeed - (decelerationRate - gravity * Mathf.Sin ((slope * Mathf.PI) / 180) * 80) * Time.deltaTime, maxFwdSpeed, 0);
}
//if no input and car is moving backward or no input and car is stagnant and is on an inclined plane with positive slope
else if ((dir == 0 && motorBack.motorSpeed > 0) || (dir == 0 && motorBack.motorSpeed == 0 && slope > 0)) {
//decelerate the car while adding the speed if the car is on an inclined plane
motorBack.motorSpeed = Mathf.Clamp (motorBack.motorSpeed - (-decelerationRate - gravity * Mathf.Sin ((slope * Mathf.PI) / 180) * 80) * Time.deltaTime, 0, maxBwdSpeed);
}
"""this is a part of code it uses the keyboard horizontal axis to determine left and right input, i want to map the keys to the touch button on android in new ui 4.6"""
Comment
Your answer
Follow this Question
Related Questions
New ui system multitouch problem 0 Answers
How do I add a value to anywhere Input.GetAxis("Horizontal") is called? 1 Answer
Unity 4.6 Button is not working. 4 Answers
Back button does nothing when keyboard is open (Android, Pixel 3 XL, unity 2019.2.7f2) 1 Answer
Problem about event triggers in iPhone 0 Answers