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
1
Question by jg2115 · Feb 02, 2014 at 03:06 AM · destroylagif-statementsplatformendless runner

2d Endless Runner: Deleting objects behind player and platform limit

I am making a 2d endless running game. I currently have a platform generating script with the following Update function:

  function Update () {
     if(platformCount!=platformCount-recycle.stdest){
     platformCount-=recycle.stdest;
     }
     if (locked==false &&platformCount<=platformCap){
     Generate();

and a script deleting previous platforms:

  #pragma strict
     var objToCheck: GameObject;
     var distance:float;
     var destroyed:int;
     static var stdest:int;

 function Update () {
 objToCheck=GameObject.FindWithTag ("platform");
  distance = Vector3.Distance(objToCheck.transform.position, transform.position);
  if (distance>100){
  Destroy(objToCheck);
  destroyed++;
  stdest=destroyed;
  }
 }
         }

It is designed to only have 30 platforms at a time, to reduce any lag. It works fine until the first platform gets deleted, then the cap becomes useless and infinite platforms are generated. Does anyone have an idea of what is going on?

EDIT: I just realized what i did(a number minus another number will never equal itself unless the number is 0) but im not sure how i should go about properly using my scripts to keep the number of platforms at 30.

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

2 Replies

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

Answer by KellyThomas · Feb 02, 2014 at 03:17 AM

GameObject.FindWithTag() will return a single object, it will return the first one it finds using it's internal algorithm, as far as we are concerned it could be any of them.

You will need to iterate though the collection returned by GameObject.FindGameObjectsWithTag() if you want to apply you logic to all of the platforms.

You may find that your record keeping could be simplified by using GameObject.FindGameObjectsWithTag().Length

Comment
Add comment · Show 2 · 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 jg2115 · Feb 02, 2014 at 04:02 AM 0
Share

okay thanks, but im having trouble getting this to work. i created the array, but how should i go about deter$$anonymous$$ing when to destroy the platform?

avatar image jg2115 · Feb 02, 2014 at 04:15 AM 0
Share

Never$$anonymous$$d, i figured it out. i made it destroy any platforms more than 30 units behind me. Thanks for the help:)

avatar image
0

Answer by Rhylvin2015 · Jul 31, 2015 at 08:07 AM

Hello I know this thread is an old one.. but ive got the same problem. Can you give me the codes that you created that you figured out.. im a clutz at creating array.

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

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

How to use a local var in the script 2 Answers

Make Animator bool false when object is destroyed 0 Answers

getchild(0), but first child is gonna be destroyed! 1 Answer

Finding any objects below or above object at ANY POINT? 1 Answer


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