1
\$\begingroup\$

I have a small game I am working on, and I am trying to add touch support to it. Before I try to add that into the real game I wanted to do a test run on a small project. The project consists of a capsule to be the player, and the application accepts movement from a on screen joystick, and accepts a button click from a UI button. The button triggers the attack, and the joystick triggers the movement.

Both of these controls work as designed but they will not work together, meaning I can do one or the other. I was hoping to use the standard asset as to not re-invent the wheel for speed...

below is the code that "Should" be triggering when both controls are used, just as a note this same code works when I use mouse and keyboard together so this is something to do with the mobile stuff..

using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;

public class PlayerController : MonoBehaviour
{
    public float playerSpeed = 10f;
    Transform weapon;

    // Use this for initialization
    void Start ()
    {
        weapon = transform.FindChild("Weapon");
    }

    // Update is called once per frame
    void Update ()
    {
        DirectionalMovements();
        ButtonPresses();
    }

    void ButtonPresses()
    {
        if (CrossPlatformInputManager.GetButtonDown("Fire1"))
        {
            weapon.GetComponent<Sword>().AttackOne();
        }
    }

    void DirectionalMovements()
    {
        float moveVertical = CrossPlatformInputManager.GetAxis("Vertical") * playerSpeed * Time.deltaTime;
        float moveHorizontal = CrossPlatformInputManager.GetAxis("Horizontal") * playerSpeed * Time.deltaTime;

        Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
        transform.Translate(movement, Space.World);

        if (movement != Vector3.zero)
        {
            transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(movement.normalized), playerSpeed);
        }
    }
}

Any thoughts would be greatly appreciated.. I just do not see why both controls are not picked up here.

\$\endgroup\$
  • \$\begingroup\$ any errors being thrown ? \$\endgroup\$ – Uri Popov Jan 24 '17 at 8:14
  • \$\begingroup\$ No errors at all, just only accepts one control or the other when using touch. But the same code works fine when using mouse and keyboard \$\endgroup\$ – user22020 Jan 24 '17 at 8:16
  • \$\begingroup\$ This is kind of a stupid question but does the device support multi touch ? \$\endgroup\$ – Uri Popov Jan 24 '17 at 8:38
  • \$\begingroup\$ Yep it does testing with a Surface Pro 4, and a Nexus 6P \$\endgroup\$ – user22020 Jan 24 '17 at 14:58
  • \$\begingroup\$ Just wanted to be clear I am using the standard asset CrossPlatformInput asset, and the SingleJoystick prefab for the controls. This has a single joystick and a button, the only change I have made to the standard prefab is renaming the Jump button to "Fire1" so that it triggers my in my code. \$\endgroup\$ – user22020 Jan 25 '17 at 19:05
0
\$\begingroup\$

not sure what fixed it but i reimported the asset package and redeployed.. this fixed it

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy