Inheritance: MonoBehaviour
	void Start () {
		parallaxScrolling = GetComponent<ParallaxScrolling>();
		cameraPosition = GameObject.FindGameObjectWithTag("MainCamera").transform.position;
		cameraWidth = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Camera>().orthographicSize * 2 * 2;
		levelCollider = this.GetComponent<Collider2D>();
		levelSizeX = levelCollider.bounds.size.x;
        levelSizeY = levelCollider.bounds.size.y;
		levelBounds = levelCollider.bounds;
	}
    void Awake()
    {
        Instance = this;
        m_layers = GetComponentsInChildren<SpriteRenderer> ();

        for(int i = 0; i < m_layers.Length; i++) {
            // Change layer sprite sorting order.
            m_layers [i].sortingOrder = i - m_layers.Length;
        }
    }
    public override void Start()
    {
        base.Start();

        globalWaypoints = new Vector3[localWaypoints.Length];
        for (int i = 0; i < localWaypoints.Length; i++)
        {
            globalWaypoints[i] = localWaypoints[i] + transform.position;
        }
        parallaxScrolling = GameObject.FindObjectOfType<ParallaxScrolling>().GetComponent<ParallaxScrolling>();
    }
        public override void OnInspectorGUI()
        {
            ParallaxScrolling script = target as ParallaxScrolling;

            if (!script.debugUseCustomEditor)
            {
                base.OnInspectorGUI();
                return;
            }

            EditorGUILayout.LabelField("Values", EditorStyles.boldLabel);
            // Scrolling axis
            script.scrollingAxis = (ParallaxScrollingAxis)EditorGUILayout.EnumPopup("Scrolling Axis", script.scrollingAxis);
            // Scrolling speed
            script.scrollingSpeed = EditorGUILayout.FloatField("Scrolling Speed", script.scrollingSpeed);
            // Static scrolling
            EditorGUILayout.LabelField("Static Scrolling", EditorStyles.boldLabel);
            script.isStaticScrolling = EditorGUILayout.Toggle("Is Static Scrolling", script.isStaticScrolling);
            if (script.isStaticScrolling)
            {
                EditorGUILayout.ObjectField("Target", script.target, typeof(Transform), true);
            }
            // Scrolling objects
            SerializedProperty scroll = new SerializedObject(script).FindProperty("scrollingObjects");

            EditorGUILayout.PropertyField(scroll, true);
            //TODO display editable array

            /*
             * if(script.scrollingObjects.Length != 0 && script.scrollingObjects != null)
             * {
             *  for(int i = 0; i < script.scrollingObjects.Length; i++)
             *  {
             *      script.scrollingObjects[i].limitLeft = EditorGUILayout.Vector3Field(script.limitAName, script.scrollingObjects[i].limitLeft);
             *  }
             * }*/

            EditorGUILayout.LabelField("Debug", EditorStyles.boldLabel);
            script.debugUseCustomEditor = EditorGUILayout.Toggle("Use Custom Editor", script.debugUseCustomEditor);
        }
        private void OnSceneGUI()
        {
            ParallaxScrolling script = target as ParallaxScrolling;
            int lineHalfLength       = 10;

            // Display scroll direction
            switch (script.scrollingAxis)
            {
            case ParallaxScrollingAxis.horizontal:
                Handles.color = Handles.xAxisColor;
                Handles.DrawDottedLine(script.transform.position - Vector3.right * lineHalfLength, script.transform.position + Vector3.right * lineHalfLength, 5);
                break;

            case ParallaxScrollingAxis.vertical:
                Handles.color = Handles.yAxisColor;
                Handles.DrawDottedLine(script.transform.position - Vector3.up * lineHalfLength, script.transform.position + Vector3.up * lineHalfLength, 5);
                break;

            default:
                break;
            }
        }
	public void UpdateTarget () {
        target = GameObject.FindGameObjectWithTag("Player").GetComponent<Controller2D>();
        player = GameObject.FindGameObjectWithTag("Player").GetComponent<Player>();
        parallaxScrolling = GameObject.FindObjectOfType<ParallaxScrolling>().GetComponent<ParallaxScrolling>();
        focusArea = new FocusArea(target.boxCollider.bounds, focusAreaSize);
    }