Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 koumeravinus · Feb 14, 2018 at 02:06 AM · 2d gamebackground

Limit looping background in 2d?

I am making 2D game. I am beginner to unity. The idea is to make the player escape from a park in limited time. I want to add zombies randomly in the park. If the player able to get out from the park in time, he will win. I want the background looping but only for 25 times. If he reach the last background, he will win. Can someone help me or give me better idea?

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

Answer by LiamofElites · Feb 14, 2018 at 03:09 AM

your post is kind of misleading, your use of the term "background". But I can help you with the looping problem

To set this up


  1. Create your zombie GameObject and a new folder in the assets folder called "Resources" this will be used for Resources.Load and Instantiate.
  2. Next drag your zombie GameObject into the Resources folder to create what is known as a prefab.
  3. Click on it so the components of the prefab show up in the inspector, on the Transform (very first) component click on the gear>Reset Position so the zombie spawns right on the spawner rather than however far away.
  4. Add the following code to a CSharp script:

SpawnerScript.cs

 int loopingLeft;
 
 int loopingTimeout;
 
 void Awake(){
     //assign in Awake just in case
     loopingLeft = 25;
     loopingTimeout = 0;
 }
 
 void Update(){
     if(loopingTimeout == 0){
         if(loopingLeft != 0){
             //clone the zombie
             //To clone the zombie drag the original "GameObject" into a new 
             folder called "Resources" so you can access and duplicate the 
             zombie using Resources.Load the gameobject you duplicated is called a prefab. The gameObject.transform is so the zombie spawns in the spawner gameobject.
             Instantiate(Resources.Load("zombie") as GameObject, gameObject.transform);
             loopingLeft--;
             loopingTimeout = 100;
         }
     }else{
         loopingTimeout--;
     }
 }


I'm more of a 3D person but for this they're the same. I hope this was helpful! Contact me if you have any questions/concerns

Comment
Add comment · Show 1 · 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
avatar image koumeravinus · Feb 14, 2018 at 04:44 AM 0
Share

Thank you very much. But what I really mean is to do the parallax repeating background but not infinite. Sorry if I confusing you. English is not my first language.

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

84 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 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 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 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 avatar image avatar image avatar image avatar image

Related Questions

2D, collision with background 0 Answers

Add multiple sprites to a background game object 1 Answer

2D Animated Background 0 Answers

How do I make the scrolling texture background change direction depending on keyboard input for the player movement controls? 3 Answers

How to how to make a different background depending on the user inputed condition? 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