Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

how to make SetTextureOffset background like this ?

Discussion in '2D' started by berke12, Jul 28, 2015.

  1. berke12

    berke12

    Joined:
    Aug 22, 2013
    Posts:
    5
  2. Zk

    Zk

    Joined:
    May 25, 2013
    Posts:
    19
    I'm not in Unity to test it now, but I would think you could do something like this in a script attached to your background material (which should probably be a child object of the camera like in that example):

    Code (CSharp):
    1. public Camera theCamera;
    2.  
    3. void Start() {
    4.  rend = GetComponent<Renderer>();
    5. }
    6.  
    7. void Update() {
    8.  rend.material.mainTextureOffset = theCamera.transform.position;
    9. }
    Edit: It seems like using the mainTextureOffset attribute is preferable to SetTextureOffset, so I modified that code to reflect that.
     
    Last edited: Aug 1, 2015
    theANMATOR2b and Leo-Yaik like this.