playMaker

Author Topic: Auto side scrolling background  (Read 3821 times)

bloodymin

  • Playmaker Newbie
  • *
  • Posts: 31
Auto side scrolling background
« on: January 21, 2013, 10:35:53 AM »
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?

gamedivision

  • Full Member
  • ***
  • Posts: 227
Re: Auto side scrolling background
« Reply #1 on: January 21, 2013, 12:05:51 PM »
do you mean parallax,if so you can get a great parallax scrolling asset of the store thats deals with just that