-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScroller.cs
More file actions
27 lines (26 loc) · 918 Bytes
/
Scroller.cs
File metadata and controls
27 lines (26 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Scroller : MonoBehaviour
{
// creating floating point number that does an offset
public float offsetFactor;
// save the start position
float startPosX;
// Use this for initialization
void Start ()
{
// go to our scroller object and get its position x
startPosX = transform.parent.position.x;
}
// Update is called once per frame
void Update ()
{
// get the position of the parent and work out how far away we are form the start
float xPos = transform.parent.position.x - startPosX;
// how much offset do we apply to the texture
float texOffset = xPos * offsetFactor;
// get our material and offset it
GetComponent<Renderer>().sharedMaterial.SetTextureOffset( "_MainTex", new Vector2( texOffset, 0.0f ) );
}
}