• 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
Question by AcE_fLoOdEr · Jan 08, 2015 at 03:45 AM · prefabspawn

Objects not spawning when I play the game on a Phone

I have a problem. When I build my game to android and deploy it to a device, some objects don't spawn at all.

The game basically spawns boxes and moves them towards the player and the player has to avoid them. The boxes don't spawn on phones, but it does when I test it on my computer. I have no idea what is going on. Below is my spawning script. It used to work before, I don't what happened.

 public class Randomize : MonoBehaviour {
 
     // --- Variable Declaration --- //
     public GameObject Prefab;
     public float objectsPerSecond = 5;
     public float MaxDistance = 5.0f;
     public float spawnTimer = 5; 
 
     // Spawn Objects
     private void spawn()
     {
         // loop based on how many objects to spawn per second
         for(int i = 0; i < objectsPerSecond; i++)
         {
             // Y axis
             float height = Random.Range(-4.0f, 4.0f);
             // X axis
             float distance = Random.Range(0, MaxDistance);
             // clone the objects
             Instantiate(Prefab);
             // move the objects
             Prefab.transform.position = new Vector2(10 + distance, height);
         }
     }
 
     void Start()
     {
         // call the spawn method to spawn the boxes.
         InvokeRepeating ("spawn", spawnTimer, spawnTimer);
     }
 }
Comment

People who like this

0 Show 0
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
Best Answer

Answer by AcE_fLoOdEr · Jan 08, 2015 at 04:47 AM

I got it.

Basically my boxes were not moving because their speed was being set to 0 at the start of the game after I added a difficulty slider. So I set the 'starting value' to a reasonable value.

Comment

People who like this

0 Show 0 · 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.

Update about the future of Unity Answers

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta later in June. Please note, we are aiming to set Unity Answers to read-only mode on the 31st of May in order to prepare for the final data migration.

For more information, please read our full announcement.

Follow this Question

Answers Answers and Comments

25 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

Related Questions

How to Spawn a Prefab over an Array of Transforms, One Prefab at a Time? 1 Answer

Enemy not spawning correctly 1 Answer

How to randomly spawn object without spawning the previous object in a row? 0 Answers

add spawned GameObjects in an array C# 1 Answer

How can I align instantiated prefabs randomly on runtime #C 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