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 blackmethod · Mar 05, 2013 at 11:06 PM · destroyviewinvisiblefield

Destroy clone when left Field of view?

I did this before but now I can't remember how I did. I have a space shooter and for performance reasons I want to destroy bullets that travel out of the Camera's visibility. Here's the current code for my gun shooting if that helps.

     var bullet : Rigidbody;
 var Spawn : Transform;
 var shotspeed : int = 1000;
 var offset = Vector3(0,0,3);
 var firingRate : float = 0.1;
 var lastFired : float = -100;
 
 function Start ()
 {
     gameObject.SetActiveRecursively(true);
 }
 
 function Update ()
 {
    
  if (Time.time < lastFired + firingRate) {
 return;
 }
     if(Input.GetButton("Fire"))
     {
        Toss();
        
     }
 }
 
 function Toss()
 {
     shot = Instantiate(bullet,Spawn.position+offset,Spawn.rotation);
     shot.rigidbody.AddForce(transform.forward * shotspeed);
      lastFired = Time.time;
 }
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
0

Answer by WilliamLeu · Mar 06, 2013 at 02:01 AM

Check if renderer.isVisible is false.

Comment
Add comment · Show 8 · 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 blackmethod · Mar 06, 2013 at 03:25 AM 0
Share

I've tried this but what do I link the destroy function to? I can't get it to destroy the clones. If i try it either doesn't work or throws the error that entities can not be deleted?

avatar image robertbu · Mar 06, 2013 at 03:29 AM 0
Share

Do you have more than one camera?

avatar image WilliamLeu · Mar 06, 2013 at 03:33 AM 0
Share

Yea, note that it only returns true if it's not visible in EVERY camera, and the editor camera counts.

avatar image robertbu · Mar 06, 2013 at 04:22 AM 0
Share

In terms of recognizing when it is no longer visible, you have a couple of choices. You can convert the position to Viewport coordinates. If x or y is less than 0 or greater than 1, then the camera is not seeing that specific point. Another way is to use these two functions:

GeometryUtility.CalculateFrustumPlanes

GeometryUtility.TestPlanesAABB

The second link as some example code of making the check.

avatar image blackmethod · Mar 06, 2013 at 04:38 AM 0
Share

Only one camera yes, the problem I'm having is pointing the destroy function to the clones of the original? The name of the original is "Pulseshot" so in the inspector I get Pulseshot(Clone) a bunch of times but I can't seem to get it to delete the clones?

What would I put in Destroy("******"); to make it destroy the clones of the object?

Show more comments

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

11 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

Related Questions

Destroy gameObject leaves behind collider? 1 Answer

How to destroy a projectile when it leaves any side of the camera view on a 2D game? 1 Answer

Placing a gameObject into, and pulling out of inventory 2 Answers

Camera frustums + custom field of view 2 Answers

Invisible Objects in Scene View 3 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