how to clone several game objects in a way that clone properties of one can be adjusted to match all others in scene view

后端 未结 8 913
执念已碎
执念已碎 2020-12-11 15:29

I asked How can I adjust shape/dimensions of one clone to affect all other clones in the scene view and the accepted answer was spot on. It could only clone one game object.

8条回答
  •  余生分开走
    2020-12-11 16:00

    use a singleton class. add that script to all the objects, then you can make a call to one and it will adjust all of them.

    you can also do this with a static class, but the singleton approach is cleaner, and gives you more options.

    public class MySingleton
    {
    
        private static MySingleton fetch; // keep the static reference private
    
        public bool myBool = false;
    
        // and expose static members through properties
        // this way, you have a lot more control over what is actually being sent out.
        public static bool MyBool { get { return fetch ? fetch.myBool : false; } }
    
        void Awake()
        {
            fetch = this;
        }
    }
    

    read here for some great information on both options!

提交回复
热议问题