- Home /
Why does the material not move with the object?
I am making a 2d game and to make movement visible to the user when there are no other objects on the screen the background needs to scroll. Currently I have an object comprising of a quad and a mesh renderer attached as a child to my camera object.
Using the code below the background follows the camera (because it is a child) and the texture scrolls in the correct direction at the correct speed. However the material that is offset does not follow the camera, leaving me with black space (with some weird streaks) once I move out of the original background area.
void Update () {
offset = (cameraLocation.transform.localPosition*scrollSpeed);
//renderer.material.SetTextureOffset("_MainTex", offset);//This has the same effect
renderer.material.mainTextureOffset = offset;
}
I cannot find any solutions in the documentation for SetTextureOffset etc and I cant find anyone else with this issue. Any help would be most appreciated.
Select the texture you are using for your background and verify that 'Wrap $$anonymous$$ode' is set to 'Repeat'.
Answer by BuzzKillingtonIII · Jan 17, 2014 at 05:11 PM
Thank you robertbu.
By setting the wrap mode to repeat this problem can be avoided. I wont need to change it so it can be done in Start(), although it could be called anywhere.
void Start () {
renderer.material.mainTexture.wrapMode = TextureWrapMode.Repeat;
}
Actually, you can just do it in the Inspector. Select the texture and change the mode. Then you don't have to do it in code.
I cant seem to find that option. Where should it appear? Its probably just me being a bit silly.
In your Project folder, select your texture (not the material).
Your answer
Follow this Question
Related Questions
Reflective/refractive 2D material, like static water. 0 Answers
Background Bitmap 3 Answers
Scrolling background help - seams appearing... 1 Answer