Scroll 2D/3D background via texture offset

浪尽此生 提交于 2019-12-02 01:26:17

Select the original Texture not the GameOBject.

1. Change Texture Type to Texture.

2. Change Wrap Mode to Repeat.

3. Click Apply. Done!

Latest version of Unity menu for Textures has changed. See the below image:

Now to animate the texture from script,

1. Create a Quad GameObject -> 3D Object ->Quad. Scale the Quad to the size you want

2. Create a light. GameObject->Light->Directional Light. You can adjust the light Intensity to whatever you like.

3. Drag your Texture/Sprite to the Quad in the Scene View.

Now for your script:

public GameObject quadGameObject;
private Renderer quadRenderer;

float scrollSpeed = 0.5f;

void Start()
{
    quadRenderer = quadGameObject.GetComponent<Renderer>();
}

void Update()
{
    Vector2 textureOffset = new Vector2(Time.time*scrollSpeed,0);
    quadRenderer.material.mainTextureOffset = textureOffset;
}

For 2D, you can also use a Plane or Quad from the GameObject ---> 3D Object menu and the code above should work fine.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!