Skip to main content
added 161 characters in body
Source Link
Hash Buoy
  • 1.5k
  • 1
  • 9
  • 17

Here is the script which takes care of what you need. Just attach to the game object where the material is assigned. You may remove this script when you are done editing the level, it wont be needed at all.

Added a few more optimization

  • Update only on change in transform
  • Update only if it is Unity editor and not in play mode
  • Scale factor

TextureResize.cs

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class TextureResize : MonoBehaviour 
{

    public float scaleFactor = 5.0f;
    Material mat;
    // Use this for initialization
    void Start () 
    {
        Debug.Log("Start");
        GetComponent<Renderer>().material.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
    }
    
    // Update is called once per frame
    void Update () 
    {
#if UNITY_EDITOR
        if (transform.hasChanged && Application.isEditor && !Application.isPlaying) 
        {
            Debug.Log("The transform has changed!");
            GetComponent<Renderer>().material.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
            transform.hasChanged = false;
        } 
#endif
    }
}

Edit:- All these things are going to be pretty straight forward with unity's upcoming updates. Hopefully it will be out soon :)

Link:- https://www.youtube.com/watch?v=muRhea-JaIM

Here is the script which takes care of what you need. Just attach to the game object where the material is assigned. You may remove this script when you are done editing the level, it wont be needed at all.

Added a few more optimization

  • Update only on change in transform
  • Update only if it is Unity editor and not in play mode
  • Scale factor

TextureResize.cs

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class TextureResize : MonoBehaviour 
{

    public float scaleFactor = 5.0f;
    Material mat;
    // Use this for initialization
    void Start () 
    {
        Debug.Log("Start");
        GetComponent<Renderer>().material.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
    }
    
    // Update is called once per frame
    void Update () 
    {
#if UNITY_EDITOR
        if (transform.hasChanged && Application.isEditor && !Application.isPlaying) 
        {
            Debug.Log("The transform has changed!");
            GetComponent<Renderer>().material.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
            transform.hasChanged = false;
        } 
#endif
    }
}

Here is the script which takes care of what you need. Just attach to the game object where the material is assigned. You may remove this script when you are done editing the level, it wont be needed at all.

Added a few more optimization

  • Update only on change in transform
  • Update only if it is Unity editor and not in play mode
  • Scale factor

TextureResize.cs

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class TextureResize : MonoBehaviour 
{

    public float scaleFactor = 5.0f;
    Material mat;
    // Use this for initialization
    void Start () 
    {
        Debug.Log("Start");
        GetComponent<Renderer>().material.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
    }
    
    // Update is called once per frame
    void Update () 
    {

        if (transform.hasChanged && Application.isEditor && !Application.isPlaying) 
        {
            Debug.Log("The transform has changed!");
            GetComponent<Renderer>().material.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
            transform.hasChanged = false;
        } 

    }
}

Edit:- All these things are going to be pretty straight forward with unity's upcoming updates. Hopefully it will be out soon :)

Link:- https://www.youtube.com/watch?v=muRhea-JaIM

deleted 12 characters in body
Source Link
Hash Buoy
  • 1.5k
  • 1
  • 9
  • 17

Here is the script which takes care of what you need. Just attach to the game object where the material is assigned. You may remove this script when you are done editing the level, it wont be needed at all.

Added a few more optimization

  • Update only on change in transform
  • Update only if it is Unity editor and not in play mode
  • Scale factor

TextureResize.cs

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class TextureResize : MonoBehaviour 
{

    public float scaleFactor = 5.0f;
    Material mat;
    // Use this for initialization
    void Start () 
    {
        Debug.Log("Start");
        this.GetComponent<Renderer>().sharedMaterialmaterial.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
    }
    
    // Update is called once per frame
    void Update () 
    {
#if UNITY_EDITOR
        if (transform.hasChanged && Application.isEditor && !Application.isPlaying) 
        {
            Debug.Log("The transform has changed!");
            this.GetComponent<Renderer>().sharedMaterialmaterial.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
            transform.hasChanged = false;
        } 
#endif
    }
}

Here is the script which takes care of what you need. Just attach to the game object where the material is assigned. You may remove this script when you are done editing the level, it wont be needed at all.

Added a few more optimization

  • Update only on change in transform
  • Update only if it is Unity editor and not in play mode
  • Scale factor

TextureResize.cs

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class TextureResize : MonoBehaviour 
{

    public float scaleFactor = 5.0f;

    // Use this for initialization
    void Start () 
    {
        Debug.Log("Start");
        this.GetComponent<Renderer>().sharedMaterial.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
    }
    
    // Update is called once per frame
    void Update () 
    {
#if UNITY_EDITOR
        if (transform.hasChanged && Application.isEditor && !Application.isPlaying) 
        {
            Debug.Log("The transform has changed!");
            this.GetComponent<Renderer>().sharedMaterial.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
            transform.hasChanged = false;
        } 
#endif
    }
}

Here is the script which takes care of what you need. Just attach to the game object where the material is assigned. You may remove this script when you are done editing the level, it wont be needed at all.

Added a few more optimization

  • Update only on change in transform
  • Update only if it is Unity editor and not in play mode
  • Scale factor

TextureResize.cs

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class TextureResize : MonoBehaviour 
{

    public float scaleFactor = 5.0f;
    Material mat;
    // Use this for initialization
    void Start () 
    {
        Debug.Log("Start");
        GetComponent<Renderer>().material.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
    }
    
    // Update is called once per frame
    void Update () 
    {
#if UNITY_EDITOR
        if (transform.hasChanged && Application.isEditor && !Application.isPlaying) 
        {
            Debug.Log("The transform has changed!");
            GetComponent<Renderer>().material.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
            transform.hasChanged = false;
        } 
#endif
    }
}
Source Link
Hash Buoy
  • 1.5k
  • 1
  • 9
  • 17

Here is the script which takes care of what you need. Just attach to the game object where the material is assigned. You may remove this script when you are done editing the level, it wont be needed at all.

Added a few more optimization

  • Update only on change in transform
  • Update only if it is Unity editor and not in play mode
  • Scale factor

TextureResize.cs

using UnityEngine;
using System.Collections;

[ExecuteInEditMode]
public class TextureResize : MonoBehaviour 
{

    public float scaleFactor = 5.0f;

    // Use this for initialization
    void Start () 
    {
        Debug.Log("Start");
        this.GetComponent<Renderer>().sharedMaterial.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
    }
    
    // Update is called once per frame
    void Update () 
    {
#if UNITY_EDITOR
        if (transform.hasChanged && Application.isEditor && !Application.isPlaying) 
        {
            Debug.Log("The transform has changed!");
            this.GetComponent<Renderer>().sharedMaterial.mainTextureScale = new Vector2 (transform.localScale.x / scaleFactor , transform.localScale.z / scaleFactor);
            transform.hasChanged = false;
        } 
#endif
    }
}