I have been trying to make an infinite scrolling 2D background in Unity using a quad to display a Texture. My idea was to change the offset of the quad depending on the player\'
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.