2020-12-22 03:13:43 +00:00
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-03-25 02:22:44 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
public class BackgroundRenderer : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
public Transform Background;
|
2020-03-29 04:19:24 +01:00
|
|
|
|
public Transform Background2;
|
2020-03-25 02:22:44 +00:00
|
|
|
|
// public float RotationSpeed1 = 1;
|
|
|
|
|
|
// public float RotationSpeed2 = 1;
|
|
|
|
|
|
private Camera _camera;
|
|
|
|
|
|
private float _ratio;
|
2020-03-25 03:15:00 +00:00
|
|
|
|
private Material _material;
|
2020-03-29 04:19:24 +01:00
|
|
|
|
private Material _material2;
|
2020-03-25 02:22:44 +00:00
|
|
|
|
private float _depth;
|
2020-03-30 03:11:57 +01:00
|
|
|
|
private float _depth2;
|
2020-03-25 02:22:44 +00:00
|
|
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
_camera = GetComponent<Camera>();
|
|
|
|
|
|
_depth = Background.position.z;
|
2020-03-30 03:11:57 +01:00
|
|
|
|
_depth2 = Background2.position.z;
|
2020-03-25 03:15:00 +00:00
|
|
|
|
_material = Background.GetComponent<MeshRenderer>().material;
|
2020-03-29 04:19:24 +01:00
|
|
|
|
_material2 = Background2.GetComponent<MeshRenderer>().material;
|
2020-03-25 02:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnPreRender()
|
|
|
|
|
|
{
|
2020-03-25 03:15:00 +00:00
|
|
|
|
_material.SetVector("ParallaxDirection", transform.position);
|
2020-03-29 04:19:24 +01:00
|
|
|
|
_material2.SetVector("ParallaxDirection", transform.position);
|
|
|
|
|
|
_ratio = (float) Screen.width / Screen.height;
|
2020-03-30 03:11:57 +01:00
|
|
|
|
Background.position = new Vector3(transform.position.x, transform.position.y, _depth);
|
|
|
|
|
|
Background2.position = new Vector3(transform.position.x, transform.position.y, _depth2);
|
2020-03-25 02:22:44 +00:00
|
|
|
|
var size = _camera.orthographicSize;
|
2020-03-29 04:19:24 +01:00
|
|
|
|
Background2.localScale = Background.localScale = new Vector3(size * 2 * _ratio, size * 2, 1);
|
2020-03-25 02:22:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|