Search Unity

Simple script works on android and pc, but not on iOS

Discussion in 'Scripting' started by Rob-Reijnen, Feb 25, 2016.

  1. Rob-Reijnen

    Rob-Reijnen

    Joined:
    Oct 14, 2013
    Posts:
    60
    Hi, I`m developing this application for iOS. I already finished it on android and is ready to publish.

    In my app I have different pages (menus). Going to a page is controlled by the following script:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PageHandler : MonoBehaviour {
    5.  
    6.  
    7.     public GameObject[] Tab = new GameObject[0];
    8.     public GameObject[] TabLayout = new GameObject[0];
    9.  
    10.     public bool ResetOnEnable;
    11.  
    12.  
    13.     public void  OnEnable(){
    14.         //Goes to the first page if the object is enabled.
    15.         if(ResetOnEnable){GoTo(0);}
    16.     }
    17.  
    18.     public void GoTo (int To)
    19.     {
    20.  
    21.         //This loop turns all the pages off.
    22.         for(int i = 0; i < Tab.Length; i++){Tab[i].SetActive(false);}
    23.  
    24.         //This loop simply places all scroll-able object on a position, so they automatically slide in when enabled.
    25.         for(int o = 0; o < TabLayout.Length; o++) {
    26.                 if (TabLayout[o] != null)
    27.                 {
    28.                 Vector3 temp = TabLayout[o].transform.position; // copy to an auxiliary variable...
    29.                 temp.y = -7680; // modify the component you want in the variable...
    30.                 transform.position = temp; // and save the modified value
    31.                 }
    32.             }
    33.  
    34.         //This turns the needed page on.
    35.         Tab[To].SetActive(true);
    36.     }
    37.  
    38. }    

    When the GoTo function is executed, all the pages (Tabs[]) seem to turn off and nothing is turned back on. It works fine on android and pc. Also works fine on pc when switched to iOS mode.
    But does not work when testing on my iphone through xcode.


    I also translated this script to Unityscript, and got the same results.
     
  2. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,089
    I'm not quite sure what you're meaning to do but shouldn't line 30 be:

    TabLayout[o].transform.position = temp;

    instead of

    transform.position = temp;

    ?
     
  3. Rob-Reijnen

    Rob-Reijnen

    Joined:
    Oct 14, 2013
    Posts:
    60
    Wow this actually fixed it. I did not expect that to happen. You were right, it should be TabLayout[o].transform.position = temp;. For me it looked like all the objects were turned off but they were actually out of place and therefore not visible.

    But now I don`t understand why my script already worked on pc and android lol.

    What I am trying to do with that code is placing the content object of a scrollrect out of view. If the scrollrect component of its parent is set to: movement type elastic. The content object will smoothly slide towards the center of the screen.

    But, thank you! Took me a whole day...
     
  4. tonemcbride

    tonemcbride

    Joined:
    Sep 7, 2010
    Posts:
    1,089
    No probs, I'm not sure why it worked on PC and Android too - maybe just something to do with the viewport size of those devices being smaller than iOS.