Search Unity

Editor script for repeating a texture over an object

Discussion in 'Scripting' started by Waigo, Oct 31, 2014.

  1. Waigo

    Waigo

    Joined:
    Jul 12, 2009
    Posts:
    49
    I wanna conver the following script to Editor script.
    This script can change the tile size based on the scale.

    Code (CSharp):
    1.  
    2. void Start(){
    3.     Vector2 SS = renderer.material.mainTextureScale;
    4.     SS.x = transform.localScale.x;
    5.     SS.y = transform.localScale.y;
    6.     renderer.material.mainTextureScale = SS;
    7. }
    I've tried this, however it doesn't work.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEditor;
    4.  
    5. public class MaterialAutoRepeatInspector : MaterialEditor {
    6.  
    7.     public override void OnInspectorGUI() {
    8.         base.OnInspectorGUI ();
    9.         if (!isVisible)    return;
    10.  
    11.         Material targetMat = target as Material;
    12.         Vector2 texScale = targetMat.mainTextureScale;
    13.         Transform targetTrans = target as Transform;
    14.         texScale.x =  targetTrans.localScale.x;
    15.         texScale.y =  targetTrans.localScale.y;
    16.         targetMat.mainTextureScale = texScale;
    17.     }
    18. }
    19.  

    Any suggestion?