- Home /
Question by
MasterRoshi80 · Nov 11, 2021 at 12:20 AM ·
gameobjectcomponent
Exposing Components to different scripts,Proper way to expose components to different scipts
Hi,
I wonder what the best way is to to expose component (ex. RigidBody2D) so I can keep control where its access, used etc.
In my example there is:
GameObject Player, with following scripts:
Player - master script, other scripts talk to each other via Player script
PlayerInput, PlayerMovement, PlayerInventory, PlayerInterface
There is rigidbody2d added to player game object.
What is the proper way to expose RB2D component to other scipts:
1 in Player script - Serialize public variable rb2d (drag it in inspector)
2 in Player script - use public variable, getcoponent on start
3 In Player script - public Rigidbody2D rb2d2 => gameObject.GetComponent();
4 just GetComponent in every script
It will work in all cases, just want to learn the best practice
Comment