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
1
Question by rodude123 · Apr 28, 2016 at 09:47 AM · 2dscripting probleminstantiategenerationinfinite

There is a generation lag

I have this script here but there is a generation lag. What I mean is the player moves up but it still doesn't generate anything for a while but then sudenly after a while it just generates a load in a few seconds and then repeats the process. So how would I change it so that it generates on time and not a load after some time. Here is the script underneath. Thanks in advance. It would be great if people could help.

 using UnityEngine;
 using System.Collections;
 
 public class Generation : MonoBehaviour {
 
     public GameObject[] barGroups;
     public float minDistanceBetweenBarGroups; 
     public float maxDistanceBetweenBarGroups;
     public Transform playerTransform;
 
     void Start () 
     {
         
     }
 
     // Update is called once per frame
     float lastPlayerPosition;
     void Update () 
     {
         //if the player 6 units distance from its last distance ,then we will create new bar group
         if( playerTransform != null && playerTransform.position.y - lastPlayerPosition > 6)
         {
 
             createNewGroup();
             lastPlayerPosition = playerTransform.transform.position.y; // to store the present ball position y .
         }
     }
 
     int groupIndex=1;
     void createNewGroup()
     {
 
         GameObject barGroupNewInstance = GameObject.Instantiate(barGroups[Random.Range (0, barGroups.GetLength(0))]) as GameObject;
         barGroupNewInstance.transform.position= new Vector3(Random.Range(minDistanceBetweenBarGroups, maxDistanceBetweenBarGroups),1.5f*groupIndex,0 ); //this will create new bars group
         groupIndex++;
     }
 }
 


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
1
Best Answer

Answer by rodude16 · Apr 28, 2016 at 10:15 AM

what you could do is change this:

 if( playerTransform != null && playerTransform.position.y - lastPlayerPosition > 6)
          {
  
              createNewGroup();
              lastPlayerPosition = playerTransform.transform.position.y;

to this:

 if( playerTransform != null && playerTransform.position.y - lastPlayerPosition > 1)
          {
  
              createNewGroup();
              lastPlayerPosition = playerTransform.transform.position.y;

this should work. Hope this helps!

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 rodude123 · Apr 28, 2016 at 08:33 PM 1
Share

Yea it did thanks it is mych faster now.

avatar image rodude16 rodude123 · Apr 28, 2016 at 08:37 PM 1
Share

You welcome I just played around with the script you gave. It was prety neat as well I have seen more unefficiant ones out there. This for me is the most effieciant I have seen so I will use this in a game I am creating

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

75 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

Related Questions

Iterate through area descibed by objects 1 Answer

Platforms are been generated more and more to the left or right 0 Answers

Mesh not being generated at all [Solved] 1 Answer

Instantiated clones using each other`s script 0 Answers

Why isn't my instance of an object moving? 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