Search Unity

How do I use Cross Platform Input Manger?

Discussion in 'Scripting' started by cuber01, Feb 22, 2017.

  1. cuber01

    cuber01

    Joined:
    Sep 16, 2016
    Posts:
    21
    I am working on a 2D Platformer and I am tring to add mobile controls

    I am trying to make it so when you touch on the joystick the player will start shooting

    I tried to change all of the input.getAxsis with CrossPlatformInputManger.getAxsis but all it did was make me not able to shoot. I also changed the build setting to IOS and made sure mobile input is enabled

    If someone could infrom me on what I am doind wrong that would be great!!

    Here is the code

    void Update ()
    {
    if (fireRate == 0)
    {
    if (CrossPlatformInputManager.GetButtonDown("Fire1"))
    {
    Shoot();
    }
    }
    else
    {
    if (CrossPlatformInputManager.GetButton ("Fire1") && Time.time > timeToFire)
    {
    timeToFire = Time.time + 1 / fireRate;
    Shoot();
    }
    }
    }

    And the Shoot method

    void Shoot ()
    {
    Vector2 joyStickPosition = new Vector2(Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).x, Camera.main.ScreenToWorldPoint(CrossPlatformInputManager.mousePosition).y);
    Vector2 firePointPosition = new Vector2 (firePoint.position.x, firePoint.position.y);
    RaycastHit2D hit = Physics2D.Raycast (firePointPosition, joyStickPosition-firePointPosition, 100, whatToHit);

    Debug.DrawLine(firePointPosition, (joyStickPosition - firePointPosition)*100, Color.cyan);
    if (hit.collider != null)
    {
    Debug.DrawLine(firePointPosition, hit.point, Color.red);
    Enemy enemy = hit.collider.GetComponent<Enemy>();
    if (enemy != null)
    {
    enemy.DamageEnemy(Damage);
    //Debug.Log("We hit " + hit.collider.name + "and did " + Damage + "damage");
    }
    }