before using 2d toolkit i used to use 3d cube and this code to move background as side scrolling.
my code is like this
using UnityEngine;
using System.Collections;
public class BG : MonoBehaviour {
public float speed = 0.1f;
public float bgHeight = 6.0f;
public float x = 0.0f;
public float y = 0.0f;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
x +=Time.deltaTime *speed;
renderer.material.mainTextureOffset = new Vector2 (x,0);
}
}
But i found out this code stands for 3d stuff
so i changed with code like this with sample
using UnityEngine;
using System.Collections;
public class Sprite : MonoBehaviour
{
private Material _material;
private Vector2 _texOffset;
void Start()
{
_material = gameObject.renderer.material;
_texOffset = _material.GetTextureOffset("_MainTex");
}
void Update()
{
_texOffset.x += Time.deltaTime;
_material.SetTextureOffset("_MainTex", _texOffset);
}
}
But none of them is not working when i trying to use background with sprite image
Please help me to solve this problem
What i want to have is automatically moving side scrolling background sprite image.
Or are there any background fsm sample for auto scrolling?