Search Unity

Camera doesnt show all scene.

Discussion in 'Scripting' started by adeemkara, Feb 16, 2019.

  1. adeemkara

    adeemkara

    Joined:
    Nov 5, 2018
    Posts:
    4
    Hello everyone. I have some issue about spritecamera class.
    Its doesnt work and camera doesnt show all scene. its show just part of scene.

    When I try to fix with drop camera oblect and resize with inspector GUI buttons stayed same place didnt get new place and I can't press it.


    this is class
    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5.  
    6.  
    7.  
    8. public class SpriteCamera : MonoBehaviour
    9. {
    10.  
    11.     private int m_Layer = 0;
    12.  
    13.  
    14.     private Transform m_Transform = null;
    15.  
    16.  
    17.     private Camera m_Camera = null;
    18.  
    19.  
    20.     private Rect m_Range = new Rect(-1.0f, -1.0f, 1.0f, 1.0f);
    21.  
    22.  
    23.     public void Initialize(int layer)
    24.     {
    25.         //
    26.         transform.position = Vector3.zero;
    27.         transform.rotation = Quaternion.identity;
    28.         transform.localScale = Vector3.one;
    29.  
    30.         //
    31.         m_Layer = layer;
    32.  
    33.         //
    34.         m_Transform = gameObject.transform;
    35.         m_Camera = (Camera)gameObject.AddComponent(typeof(Camera));
    36.  
    37.         //
    38.         m_Transform.position = Vector3.zero;
    39.         m_Transform.LookAt(Vector3.zero, Vector3.up);
    40.  
    41.         //
    42.         m_Camera.clearFlags = CameraClearFlags.Nothing;
    43.         m_Camera.backgroundColor = Color.black;
    44.         m_Camera.nearClipPlane = -1.0f;
    45.         m_Camera.farClipPlane = 1.0f;
    46.         m_Camera.orthographic = true;
    47.         m_Camera.aspect = 1.0f;
    48.         m_Camera.orthographicSize = 1.0f;
    49.         m_Camera.depth = 0;
    50.         m_Camera.cullingMask = (1 << m_Layer);
    51.     }
    52.  
    53.  
    54.     public void SetClear(bool clear)
    55.     {
    56.         if (clear)
    57.         {
    58.             m_Camera.clearFlags = CameraClearFlags.SolidColor;
    59.         }
    60.         else
    61.         {
    62.             m_Camera.clearFlags = CameraClearFlags.Nothing;
    63.         }
    64.     }
    65.  
    66.  
    67.     public void SetDepth(float depth)
    68.     {
    69.         m_Camera.depth = depth;
    70.     }
    71.  
    72.  
    73.     public void SetViewport(Rect range)
    74.     {
    75.  
    76.  
    77. #if UNITY_IPHONE
    78.         m_Transform.position = new Vector3((range.xMin + range.xMax) / 2, (range.yMin + range.yMax) / 2, 0);
    79. #else // Win32
    80.         m_Transform.position = new Vector3((range.xMin + range.xMax + 1) / 2, (range.yMin + range.yMax - 1) / 2, 0);
    81. #endif
    82.  
    83.         m_Camera.aspect = range.width / range.height;
    84.         m_Camera.orthographicSize = range.height / 2;
    85.  
    86.         m_Range = range;
    87.     }
    88.  
    89.  
    90.     public Vector2 ScreenToWorld(Vector2 point)
    91.     {
    92.  
    93.  
    94.         return new Vector2(m_Range.x + point.x / Screen.width * m_Range.width, m_Range.y + point.y / Screen.height * m_Range.height);
    95.  
    96.     }
    97. }
    98.  
    99.  
    and this is issue screenshot