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 whidzee · Jun 01, 2016 at 03:54 PM · listscalefindname

find all objects with a particular name that have been scaled

I am quite new to c#

Some of my objects have been scaled up in Y to get some variation. I am wanting to find all of these models and put them in a list so I can easily select them and go right to them.

So assuming the name of the model has the word "Tree" in it. How can I go about selecting all of them that have had their scales adjusted?

I believe this is going to be a pretty simple script, but finding the correct syntax for this has been driving me up the wall.

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 Soos621 · Jun 01, 2016 at 04:08 PM

You want to attach the tree class to all the the trees in the scene. Then place the treemanager into an object anywhere. The tree will register itself with the manager class and the manager class will sort out the tree that are scaled and if you so choose how much they have been scaled

 public class Tree (){

     public bool hasBeenScaled;
     public float scaleAmount;
     private TreeManager tManager;

     void Awake (){
         /* there are much better ways of having the treemanager class reference found
         but this will be fine */

         tManager = GameObject.FindObjectWithType<TreeManager> ();
         RegisterCurrentTree ();
     }

     void RegisterCurrentTree (){
         tManager.RegisterTree(this);
     }
 }

 public class TreeManager (){
     // you need to use System.Collections.Generic to use lists and dictionaries
     public List <Tree> allTrees = new List<Tree>();

     public void RegisterTree (Tree _tree){
         if(!allTrees.contains(_tree)){
             allTrees.add(_tree);
         }
     }

     public List<Tree> FindAllScaledTrees (){
         List<Tree> scaledTrees = new List<Tree>();
         foreach(Tree t in allTrees){
             if(t.hasBeenScaled){
                 scaledTrees.add(t);
             }
         }
         return scaledTrees;
     }

     public List<Tree> FindAllScaledTrees (float minScale, float maxScale){
         List<Tree> chosenScaledTrees = new List<Tree>();
         foreach(Tree t in allTrees){
             if(t.hasBeenScaled){
                 if(t.scaleAmount >= minScale && t.scaleAmount <= maxScale){
                     chosenScaledTrees.add(t);
                 }
             }
         }
         return chosenScaledTrees;
     }
 }
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 whidzee · Jun 01, 2016 at 05:37 PM 0
Share

is there any way to do this without adding a tree class to each tree? no way to search for them by their name?

something along the lines of GameObject = GameObject.Find("tree")

avatar image Soos621 whidzee · Jun 01, 2016 at 06:37 PM 0
Share

yes but it is very impractical and slow. What you really want to do when you set up an environment in unity is to make a prefab of each object that you place in the scene, then use those prefabs to build the level that way when something like this comes along where say you need to add a script to every tree or rock you can just add the new script as a component to the prefab and all of the objects will update with that script

the only way i would know about finding all the trees in the scene would to tag them as "tree" and then gather every gameobject in the scene go through each one and check the tag then add it to the correct list, but you wont be able to figure out how much each tree has scaled either

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

59 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

Related Questions

Getting the Index number of lowest 7 ints in list 3 Answers

Getting list to print correctly and collider raycast to not get an error when i read first object to second object 0 Answers

Find GameObjects With Tag only in a scene. 0 Answers

New Here: How do I resize(scale) based on set numbers [Such as by 1.5 when I drag?] 0 Answers

Dynamically adjust any plane infront of Camera 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