Search Unity

iPhone X screen act as non-notched device

Discussion in 'Scripting' started by Gdakkutlu, May 23, 2019.

  1. Gdakkutlu

    Gdakkutlu

    Joined:
    Nov 9, 2016
    Posts:
    47
    Hey;

    I recently use the screen corners as a collider with a script.
    But the problem is notch.
    Script allows me to automatically define and create colliders surround the screen.
    But when notch devices has a different top shape then other ones, i think this might be a problem.

    When I check the game in 1080 x 1920 in editor, all good.
    So I just want my game in iphone x and above act like iphone 8 and before.

    Or how can i ignore the area on top of the notch and act like its a 1080x1920 resolution.

    Here is the script I used for screen colliders. (found it online)
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class corners : MonoBehaviour
    6. {
    7.     public static int score;
    8.        public float colDepth = 1f;
    9.     public float zPosition = 0f;
    10.     private Vector2 screenSize;
    11.     private Transform topCollider;
    12.     private Transform bottomCollider;
    13.     private Transform leftCollider;
    14.     private Transform rightCollider;
    15.    
    16.     private Vector3 cameraPos;
    17.    
    18.  
    19.     void Start () {
    20.  
    21.        
    22.  
    23.         topCollider = new GameObject().transform;
    24.         bottomCollider = new GameObject().transform;
    25.         rightCollider = new GameObject().transform;
    26.         leftCollider = new GameObject().transform;
    27.         topCollider.name = "TopCollider";
    28.         bottomCollider.name = "BottomCollider";
    29.         rightCollider.name = "RightCollider";
    30.         leftCollider.name = "LeftCollider";
    31.      
    32.  
    33.         topCollider.gameObject.AddComponent<BoxCollider2D>();
    34.         bottomCollider.gameObject.AddComponent<BoxCollider2D>();
    35.         rightCollider.gameObject.AddComponent<BoxCollider2D>();
    36.         leftCollider.gameObject.AddComponent<BoxCollider2D>();
    37.      
    38.    
    39.  
    40.         topCollider.parent = transform;
    41.         bottomCollider.parent = transform;
    42.         rightCollider.parent = transform;
    43.         leftCollider.parent = transform;
    44.          
    45.  
    46.  
    47.  
    48.         cameraPos = Camera.main.transform.position;
    49.         screenSize.x = Vector2.Distance (Camera.main.ScreenToWorldPoint(new Vector2(0,0)),Camera.main.ScreenToWorldPoint(new Vector2(Screen.width, 0))) * 0.5f;
    50.         screenSize.y = Vector2.Distance (Camera.main.ScreenToWorldPoint(new Vector2(0,0)),Camera.main.ScreenToWorldPoint(new Vector2(0, Screen.height))) * 0.5f;
    51.      
    52.    
    53.         rightCollider.localScale = new Vector3(colDepth, screenSize.y * 2, colDepth);
    54.         rightCollider.position = new Vector3(cameraPos.x + screenSize.x + (rightCollider.localScale.x * 0.5f), cameraPos.y, zPosition);
    55.         leftCollider.localScale = new Vector3(colDepth, screenSize.y * 2, colDepth);
    56.         leftCollider.position = new Vector3(cameraPos.x - screenSize.x - (leftCollider.localScale.x * 0.5f), cameraPos.y, zPosition);
    57.         topCollider.localScale = new Vector3(screenSize.x * 2, colDepth, colDepth);
    58.         topCollider.position = new Vector3(cameraPos.x, cameraPos.y + screenSize.y + (topCollider.localScale.y * 0.5f), zPosition);
    59.         bottomCollider.localScale = new Vector3(screenSize.x * 2, colDepth, colDepth);
    60.         bottomCollider.position = new Vector3(cameraPos.x, cameraPos.y - screenSize.y - (bottomCollider.localScale.y * 0.5f), zPosition);
    61.  
    62.     }
    63.  
    64. }
    65.  
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,162
    There's an notch option in build settings, you may check it so your app will ignore notch.
     
  3. Gdakkutlu

    Gdakkutlu

    Joined:
    Nov 9, 2016
    Posts:
    47
    Thanks for answer.
    I couldn't manage to find that option in Unity and xCode.
    Googled it too, but no results tho.

    Can you tell me where is that option?
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,162
    Build Settings > Player Settings > Resolution and Presentation > Render outside safe area