Last active
July 19, 2016 16:25
Revisions
-
Johan Johansson renamed this gist
Jul 19, 2016 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
Johan Johansson created this gist
Jul 19, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ using UnityEngine; using System.Collections; [ExecuteInEditMode] public class QuadTextureScaler : MonoBehaviour { private Renderer rend; private float textureWidthInUnits; private float textureHeightInUnits; private float pixelsPerUnit; private void Start() { rend = GetComponent<Renderer>(); Texture texture = rend.material.mainTexture; pixelsPerUnit = Screen.height / (Camera.main.orthographicSize * 2); textureWidthInUnits = texture.width / pixelsPerUnit; textureHeightInUnits = texture.height / pixelsPerUnit; } private void Update () { rend.material.mainTextureScale = new Vector2(transform.localScale.x / textureWidthInUnits, transform.localScale.y / textureHeightInUnits); } }