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
0
Question by androids · Oct 16, 2013 at 01:09 AM · objectdestroymaincamerabehind

Destroy GameObject behind the Main Camera

Hi guys,

I made 1 straight road where the character with Main Camera moves only forward. What I'm trying to do is to destroy all the objects behind the Main Camera without using Occlusion Culling.

Someone knows how to do that?

Please help.

Thanks in advance

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 Eric5h5 · Oct 16, 2013 at 03:05 AM

Depending on how your game actually works, put this script on each object:

 function OnBecameInvisible () {
     Destroy (gameObject);
 }
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 androids · Oct 22, 2013 at 12:28 AM 0
Share

I tried this. But it doesn't work :S

avatar image
4

Answer by whydoidoit · Oct 16, 2013 at 01:25 AM

Yep:

   //Presuming you have the item to be tested in a variable called "item"

   float distanceToCull = 4f;

   var cameraPosition = Camera.main.transform.position;
   var vectorToItem = (item.position - cameraPosition);
   if(Vector3.Angle(vectorToItem, Camera.main.transform.forward) > 90) //It's behind us
   {
        //Perhaps ensure it's far enough away
        if(vectorToItem.sqrMagnitude > distanceToCull * distanceToCull)
        { 
            //Kill it
        }
   }
Comment
Add comment · Show 4 · 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 androids · Oct 20, 2013 at 08:00 PM 0
Share

Unity gives me an error. I tried a lot. But nothing helps. Can you help me please?

This is the error

Assets/Scripts/scr_s1ingame/level04/NewBehaviourScript.js(1,6): UCE0001: ';' expected. Insert a semicolon at the end.

avatar image whydoidoit · Oct 20, 2013 at 08:17 PM 0
Share

Going to need to see the code

avatar image androids · Oct 20, 2013 at 08:29 PM 0
Share

This is the code

 float distanceToCull = 4f;
  
   var cameraPosition = Camera.main.transform.position;
   var vectorToItem = (item.position - cameraPosition);
   if(Vector3.Angle(vectorToItem, Camera.main.transform.forward) > 90) //It's behind us
   {
        //Perhaps ensure it's far enough away
        if(vectorToItem.sqr$$anonymous$$agnitude > distanceToCull * distanceToCull)
        { 
            //$$anonymous$$ill it
        }
   }


The error is in this line

 float distanceToCull = 4f;
avatar image androids · Oct 20, 2013 at 08:49 PM 0
Share

Ok I found it. It's

 var distanceToCull : float = 4f;

I added a var into this js

 var item : Transform;

And when I attach the item to the var in the inspector Unity gives me this error

UnityException: You are not allowed to call this function when declaring a variable. $$anonymous$$ove it to the line after without a variable declaration. If you are using C# don't use this function in the constructor or field initializers, Ins$$anonymous$$d move initialization to the Awake or Start function. UnityEngine.Component.get_transform () (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/UnityEngineComponent.cs:21) NewBehaviourScript..ctor () (at Assets/Scripts/scr_s1ingame/level04/NewBehaviourScript.js:5)

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

16 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

Related Questions

Pick up objects 2 Answers

Dispose Object in IOS 0 Answers

Destroy the current GameObject? 7 Answers

How to remove an object from an array once it has been destroyed 1 Answer

How to get the constant Y rotation of the camera 2 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