Search code examples
c#unity-game-engineunityscriptunity3d-2dtools

Unity 2d, access component from code


I have components in my player object like:

enter image description here

How can I acces in PlayerMovement.cs that RigidBody? How can I find it?

Thanks!


Solution

  • Create a Rigidbody object like

    Rigidbody object;
    

    and use

    object = GetComponent<Rigidbody>();
    

    in Start() method. This works for Unity 5