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
0
Question by butigirilla · Jan 13, 2019 at 02:43 AM · y axis

Deleting a specific name if it passes through the -5 y axis

I want to create a script where if the name of a gameObject is "Hi" and that gameObject goes through the -5 y axis it will be destroyed.

i've spent alot of time on this and i've actually tried. please unity explain

Comment
Add comment · Show 3
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 sean244 · Jan 13, 2019 at 04:55 AM 0
Share

You mean if it's transform.position.y <= -5?

avatar image butigirilla sean244 · Jan 13, 2019 at 05:33 AM 0
Share

yes, sure...

avatar image sean244 butigirilla · Jan 13, 2019 at 05:35 AM 0
Share

Do all of the 'Hi' gameObjects already have their own script attached to them?

2 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by DCordoba · Jan 13, 2019 at 09:04 AM

name of the object is a weird mode to search object. because the system add a (clone) when instantiate, and the system have to compare each gameobject.name consuming a lot resources and maybe freezing the cpu

If u are new I suggest to use tag , and GameObject.FindGameObjectWithTag( "Hi") or better, manage a dynamic array, can be a ArrayList or List and get access to all "Hi" objects instantly, however, if U know what are you doing here is a small script

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class FindHI : MonoBehaviour {
     Transform[] AllHi;
     bool SafeValve = false; //this is to stop overload of the cpu, if happens hold space
     // Use this for initialization
     /*void Start () {
         
     }*/
     
     // FixedUpdate is called each Time.fixedDeltaTime seconds
     void FixedUpdate () {
         //to test pupose, hold space to stop cpu overloading
         if(Input.GetKey(KeyCode.Space))
             SafeValve = true;
         if (!SafeValve) { 
             //thats the first problem, this get all objects
             AllHi = GameObject.FindObjectsOfType<Transform> ();
             //thats the other problem, a loop iterates trough all objects on scene
             foreach(Transform Hi in AllHi)
                 if (Hi.position.y<-5 && Hi.name == "Hi")
                     Destroy (Hi.gameObject);
         }
     }
 }
 

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 sean244 · Jan 13, 2019 at 09:36 AM 0
Share

Why FixedUpdate? The input will not always be detected if the code isn’t running at every frame.

avatar image DCordoba sean244 · Jan 13, 2019 at 10:48 AM -1
Share

its teorically true, interesting, it must not detect it, but in fact it does, even with low framerate, idk the reason, but, in case of fail, I put "hold" there, so I hope it will catch the imput sometimes.

After do the script I put the safe, in the script without the safe the election was because the delete is based on movement. I guess he need to use it on objects moved by physics/ transforms with deltatime correction, because of that, is better to delete it on fixeddeltatime... other solution is put a massive collider on the -5, still will consume less resources... well, depend the amount of transforms on scene... and collisions per second...

avatar image sean244 DCordoba · Jan 13, 2019 at 11:20 AM 0
Share

It’s not theoretical. There’s going to be times when the input is not going to be detected. I’ve had this problem before, and so have many other people (you can google it if you don’t believe me). Putting input in FixedUpdate will occasionally lead to input loss.

avatar image sh_code · Jan 13, 2019 at 08:19 PM 0
Share

DO NOT DO any FindObjects or GetComponent in update functions!

EVER!

It's slow as hell and stupid as hell! Either find them all in Awake/Start, or if they are created at runtime, make them register themselves to the script which handles their destroying

avatar image
0

Answer by butigirilla · Jan 13, 2019 at 06:16 PM

More of curiosity than actually making something... Was using GameObject instead of Transform.

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 butigirilla · Jan 13, 2019 at 06:34 PM 0
Share

Still doesn't work btw

avatar image sean244 · Jan 13, 2019 at 07:40 PM 0
Share

Is there a script attached to the 'Hi' gameobject?

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

99 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

Related Questions

My rigidbody's y rotation is always 180 1 Answer

how can i lock y position of a player when its being dragged? 1 Answer

Character rotation to a specific degree 2 Answers

Following the Y Axis Rotation of another Object 1 Answer

Gun stretches when rotated 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