Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by pokobros · Feb 17, 2014 at 12:43 AM · shaders

Infinite scrolling background

I am trying to make a game with the same scrolling background like Subway Surfers. How would you be able to do this with Unity? I am just starting out so I do not have much information, but from what I can see on other forum posts is that you would need a shader. I am 13 years old and this is the first game I am programming with Unity, so code examples are very very helpful. Thank you.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by erick_weil · Feb 17, 2014 at 01:35 AM

try to adapt this code to your neededs, create a new scene, add a cube, set the cube scale.x to 2 and scale.z to 2 too put the script on the camera, asign the object variable with your created cube and have fun!

 #pragma strict
 var objectprefab : GameObject;
 var whatIhavehere : GameObject[];
 var objectscalez : float = 2;
 var objectscalex : float = 2;
 var numberofobjects : int;
 var zoffset : float = 2;
 var yoffset : float = -2;
 var z : int;
 var proxblock : int;
 var centerx : float; 
 function Start () {
 
 numberofobjects = 5; 
 whatIhavehere = new GameObject[numberofobjects*10];
 
 transform.position.z += 3*Time.deltaTime;
 z =Mathf.FloorToInt(transform.position.z);
 proxblock = z+numberofobjects;
  centerx = transform.position.x;
 }
  
  
 function Update () 
 {
  
 // transform a float position in a int position,
 z =Mathf.FloorToInt(transform.position.z);
 if(z+(numberofobjects) == proxblock)
 {
 var posi : Vector3;
 posi = Vector3( centerx,transform.position.y+yoffset,z+(numberofobjects*objectscalez)+zoffset);
     whatIhavehere[foundone()] =Instantiate(objectprefab,posi,objectprefab.transform.rotation);
     whatIhavehere[foundone()] =Instantiate(objectprefab,posi-Vector3(objectscalex,0,0),objectprefab.transform.rotation);
     whatIhavehere[foundone()] =Instantiate(objectprefab,posi+Vector3(objectscalex,0,0),objectprefab.transform.rotation);
     proxblock += objectscalez;
 }
 
        if(Input.GetKeyDown ("a")&& transform.position.x >= centerx )
        {
        moveTo(transform.position.x - 1.5, 20); //Feed the moveTo() function the X/Y positions you want it to move to, and the Speed you want it to move at
        }
 
        if(Input.GetKeyDown ("d")&& transform.position.x <= centerx )
        {
        moveTo(transform.position.x + 1.5, 20); //Feed the moveTo() function the X/Y positions you want it to move to, and the Speed you want it to move at
        }
       
  transform.position.z += 3.0*Time.deltaTime;      
 }
  
 function moveTo(posX : float, speed : float)
 {
     while(posX!= transform.position.x)
        {
          transform.position = Vector3.MoveTowards (transform.position,new Vector3(posX,transform.position.y,transform.position.z),speed * Time.deltaTime);
          yield;
        }
 
 }
  
 function foundone () 
 {
     for(var i=0;i<whatIhavehere.Length;i++)
     {
        if(whatIhavehere[i] == null)
          return(i);
        else
        {
          if((whatIhavehere[i].transform.position.z -z)<z-proxblock)
          {
           Destroy(whatIhavehere[i]);
           return(i);
          }
        }
     }
     return(i);
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GrabPass and transparent Queue materials 0 Answers

Best way to achieve a vector graphics effect? 2 Answers

Doom Classic Effect - Realtime Pixelated Shadows 1 Answer

shader problem 0 Answers

Unity 5 and PhysX shaders. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges