- Home /
Question by
TGKG · Mar 16, 2017 at 08:31 PM ·
inputcrossplatform
Unity Standard asset Cross Platform Input Manager and mouse input
I am using the Unity Cross Platform Input manager and the Single Stick Control joystick. How do I test the Joystick from the Editor and using my mouse to move the joystick.
If I enable the mobile Input, I can see the joystick and my mouse will move the joystick, yet the script does not move the game object.
If I disable the mobile Input, I no longer can see the joystick, yet my mouse clicks and movements move my game object.
My code looks like this.
void Update()
{
// pass the input to the car!
float h = CrossPlatformInputManager.GetAxis("Horizontal");
float v = CrossPlatformInputManager.GetAxis("Vertical");
touchHeading = new Vector2(h, v);
#if !MOBILE_INPUT
//When the Mouse first is pressed DOWN, set the start point
if (Input.GetMouseButtonDown(0))
{
//get the screen coordinates of the touch
touchPtScreen = CrossPlatformInputManager.mousePosition;
//save the starting touch point in SCREEN SPACE
startTouchPt = touchPtScreen;
}
if (Input.GetMouseButton(0) && CrossPlatformInputManager.mousePosition != startTouchPt)
{
print("Mouse MOVED = " + CrossPlatformInputManager.mousePosition);
if (Vector2.Distance(CrossPlatformInputManager.mousePosition, startTouchPt) > touchSensitivity)
{
touchHeading = CrossPlatformInputManager.mousePosition - startTouchPt;
lastHeading = touchHeading;
}
}
#endif
//MOBILE DPAD control
#if MOBILE_INPUT
if (Input.touchCount > 0)
{
if (Input.GetTouch(0).phase == TouchPhase.Began || Input.GetTouch(0).phase == TouchPhase.Moved)
{
if (Input.GetTouch(0).deltaPosition.magnitude > touchSensitivity)
{
lastHeading = touchHeading;
}
}
}
#endif
//this will move the car in the heading of the DPAD heading and will continue to move in that direction
my2DLookAt(lastHeading);
my2DMoveTowards(lastHeading);
Comment