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 /
  • Help Room /
avatar image
0
Question by Raitrow · Jan 21, 2020 at 11:07 PM · arrayobjectspawnprefabsspawning problems

spawning problems, using array for random objects,Spawning rand prefab from array, destroy when not in the view of camera, roll new one.

Soo... How to put it. I've spent 5 hours sitting on it for now (and some other things) and cannot find any clue. I hope there is somewhere a good soul that will help me somehow.

Setup: I have a player and a planet; the planet is covered with spawn points. The player is running around that planet (you know, like orbiting on it). The camera is placed behind the player and follows him.

  1. There goes the problem: there are 3 scripts: isThisVisible, object_roller, destroyer.

  2. isThisVisible and object_roller are placed on spawn points which NEVER got destroyed. destroyer is placed on a spawned object and as name reminds is just destroys an object whenever is outside of the camera view.

  3. Basically everything works fine, objects are spawned in the start method and even disappear when not seen in camera view, but then it seems like every spawnpoint just looses his object_roller and only 1 spawnpoint spawns objects.

I really hope you understand me. If some1 was that into my problem i could rec a vid and upload on yt to more clear explanation.

Here goes the code:

 public class object_roller : MonoBehaviour
 {
     public GameObject[] objectPrefabs;
     public static bool objSpawned = false;
     int index;
     public static bool onOff = true;
 
     private void Start()
     {
         index = Random.Range(0, objectPrefabs.Length);
         Instantiate(objectPrefabs[index], transform.position, transform.rotation);
         objSpawned = true;
     }
 
     private void Update()
     {
         if (onOff)
         {
             if (objSpawned == false)
             {
                 index = Random.Range(0, objectPrefabs.Length);
                 Instantiate(objectPrefabs[index], transform.position, transform.rotation);
                 objSpawned = true;
             }
         }
     }
 }

 public class IsThisVisible : MonoBehaviour
 {
     public static bool isVisible;
     Renderer rend;
 
     private void Start()
     {
         rend = GetComponent<Renderer>();
         StartCoroutine(visibility());
     }
 
     public IEnumerator visibility()
     {
         if (rend.IsVisibleFrom(Camera.main))
         {
             Debug.Log("#isThisVisible:isVisible: True");
             isVisible = true;
             yield return new WaitForSeconds(0.5f);
         } else
         {
             Debug.Log("#isThisVisible:isVisible: False");
             isVisible = false;
             yield return new WaitForSeconds(0.5f);
         }
     }
 }

 public class destroyer : MonoBehaviour
 {
     Renderer rend;
 
     private void Start()
     {
         rend = GetComponent<Renderer>();
     }
     void Update()
     {
         if (rend.IsVisibleFrom(Camera.main))
         {
             Debug.Log("#destroyer:isVisible: True");
         }
         else
         {
             object_roller.objSpawned = false;
             Destroy(gameObject);
         }
     }
 }

I would be SUPER thankful if somebody was able to help me I have no clue what does it and how to get rid of it.

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

0 Replies

· Add your reply
  • Sort: 

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

221 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 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 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

Can I spawn with an array in order? 2 Answers

Random array with prefabs? 2 Answers

Multiplayer: 4 players, each player spawning less amount of other players. 0 Answers

Unity2D: How to destroy spawned object once it exit out of camera's view? 1 Answer

problem when i spawn to many Enemy the game be slower 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