Set properties to a group of objects
Hi everyone, I'm very new to Unity so go easy on me :). I am trying to create a board game where I have units and my opponent has some of his own. Now I want to apply gravity and a collision detection to all the units but I don't want to do it manually, I orgenized then in a group and I want to apply a script to that group that will enable gravity and collision detection. How can I do that? I'm a programmer so don't be afraid to show me some codes or if you guys can help me find a source where I can learn Unity from that would be awsome.
Gravity : handled by Rigidbody component, collision detection handled by Rigidbody + Collider.
Can't you simply add those components and enable / disable them when needed?
Answer by tutaBugarin · Aug 15, 2020 at 05:06 PM
You can learn basic scripting in Unity C# from Unity Learn Premium (completely free)
https://unity.com/products/learn-premium
and everything (scripting and using the Unity Engine) from Unity documentation:
If you want to add gravity and collision detection fast, just hold Ctrl and select all game objects you want to apply it, then add Rigidbody and a corresponding collider.
Answer by epicpython · Aug 17, 2020 at 06:06 PM
You should look into Prefabs. https://docs.unity3d.com/Manual/Prefabs.htmlDocumentation/Manual/Prefabs.html#:~:text=You%20can%20create%20a%20prefab,gameobject%20with%20the%20new%20one.
Basically, once you make a prefab, it is easy to make copies of it. So let's say you figure out how to make one board game unit for your game,you write some code, get the colliders set up,everything is perfect. You can then create a prefab of it. Then if you want another copy, it's super easy to make another copy of the prefab.
Then, say, later on, you decide you need to change something about the board game unit. Maybe it's red and you want it to be blue. You can change individual copies (make some red, some blue). You can also change the prefab itself- say, if all of your copies are red, and you want them all to be blue, you can just change the prefab. This is really nice because you don't have to change each copy individually!
Check out this tutorial video on prefabs: https://www.youtube.com/watch?v=0Jc287z4Qpg
Hope this helps!
Your answer
Follow this Question
Related Questions
Collision detection in 2017 3d 4.2f2 0 Answers
GameObject collision with screen 0 Answers
Check if a large number of gameobjects are colliding 1 Answer
Object refuses to collide 0 Answers
ontriggerexit not working 0 Answers