2
votes

Unity has this sample project "Roll a Ball" at this link: https://unity3d.com/learn/tutorials/projects/roll-ball-tutorial

I have been able to build and make it work 100% well on my Mac. I am able to use the arrow keys on the keyboard to move the ball. Everything works on the Mac platform.

However, when I use the same code to build and deploy this game on my iPad, I notice that the ball does not move at all when I use my fingers to try to move the ball. (The only good thing is that all the cubes are rotating well)

So, my question is if I need to modify the C# script for the ball to make it works for iPad (although that script already works for Mac) ?

Here is the C# script for the ball:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerController : MonoBehaviour
{

    public float speed;
    public Text countText;
    public Text winText;

    private Rigidbody rb;
    private int count;

    void Start ()
    {
        rb = GetComponent<Rigidbody>();
        count = 0;
        SetCountText ();
        winText.text = "";
    }

    void FixedUpdate ()
    {
        float moveHorizontal = Input.GetAxis ("Horizontal");
        float moveVertical = Input.GetAxis ("Vertical");

        Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);

        rb.AddForce (movement * speed);
    }

    void OnTriggerEnter(Collider other) 
    {
        if (other.gameObject.CompareTag ( "Pick up"))
        {
            other.gameObject.SetActive (false);
            count = count + 1;
            SetCountText ();
        }
    }

    void SetCountText ()
    {
        countText.text = "Count: " + count.ToString ();
        if (count >= 12)
        {
            winText.text = "You Win!";
        }
    }
}

*Interestingly, I have just noticed that the type INPUT has the method "GetTouch()". Maybe, I could try to use that method for iPad ? Initially, I was hoping that the generic code in the C# script above that works for Mac could also work for iPad ? Maybe, my assumption was wrong and I need to write a different set of code with "GetTouch()" for iPad ? OK, I am thinking that is the possible solution, and will try that now... *

PS: BTW, I am using the latest Unity (version 5.5.2f1) and latest XCode (8.2.1) as of Feb 2017. The iOS on my iPad is also the latest (version 10.2.1).

2

2 Answers

1
votes

I have never create anything for iPad in Unity, but with the description you provided I think the problem is not in your script. I would recommend you instead to check if everything is properly linked in the input Manager (Edit->Project Settings->Input)

https://docs.unity3d.com/Manual/class-InputManager.html

I think the problem is the game is not detecting your inputs from the iPad. You can try to add a constant speed in x axis to the ball, and if it moves, you can focus your efforts in Input Manager.

Additionally, check this link: http://wiki.unity3d.com/index.php?title=Basic_iOs_Input_Tutorial

1
votes

You have to change the input settings. I don't know exactly where to find them, but then you can change the inputs "horizontal" and "vertical". you should take a look at this more, because you can also add inputs, which is very useful if you want to have all power over the controls of you game.

Oh found it just look at the previous answer.