Material

renderer.material  物理材质

实现二维图上的人物动作

新建Material,选择Shader(著色器)为transparent/diffuse(背景透明),将上图拉到背景图选项中。

创建plane(片),将片的材质改为新建的material,调整tiling  x和y的值(为1/列数和1/行数),offset为偏移量

mainTextureScale(Vector2)纹理缩放

    int i ;
    int j ;
    public int w, h ;//w,h可变,适应其它图片
    public float stepTime ;
    // Use this for initialization
    void Start () {
        renderer.material.mainTextureScale = new Vector2(1f/(float)w, 1f/(float)h) ;
    }
    
    // Update is called once per frame
    void Update () {
        if(Time.time>stepTime){
            renderer.material.mainTextureOffset = new Vector2(1f/(float)w*i, 1f/(float)h*j) ;
            if(i+1>=w) j = (j+1)%h ;
            i = (i+1)%w ;
            stepTime = Time.time + 0.5f ;
        }
    }
原文地址:https://www.cnblogs.com/xiaolongchase/p/3275455.html