新建一个2D精灵 实体,使其Transform的LocalScale 为1,1,1。
设置组件SpriteRenderer的Sprite,DrawMode设置为Tiled,不改变Size的 Height,仅改变 Size的Width,即 水平平铺。
设置组件SpriteRenderer的Sprite,DrawMode设置为Tiled,不改变Size的 Width,仅改变 Size的Height,即 垂直平铺。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class TestSprite : MonoBehaviour
{
public SpriteRenderer spriteRenderer;
public Texture2D tex;
// Start is called before the first frame update
void Start()
{
init2DSprite();
}
private void init2DSprite()
{
spriteRenderer = this.GetComponent<SpriteRenderer>();
tex = spriteRenderer.sprite.texture;
spriteRenderer.drawMode = SpriteDrawMode.Tiled;
spriteRenderer.size = new Vector2(100, spriteRenderer.size.y);
}//
}//