Unity - Move the Player Using Scripts Part 1

Matthew·2024년 8월 20일
0

Unity

목록 보기
5/9

Awake()

public class PlayerMove : MonoBehaviour
{
    Rigidbody2D rigid;

      private void Awake()
    {
        rigid = GetComponent<Rigidbody2D>();
    }

   
}
  • Get the gameObject's Rigidbody2D componenet and set name for it. For this case it's rigid, but you can call it however you want like rb or body2D.

  • In the Awake(), use GetComponent<> to access and manipulate the component. We're going to manipulate Rigidbody2D here so I did

rigid = GetComponenet<Rigidbody2D>();

Make sure to put () after the <> to complete the code.

Now we can move on to actually writing the code so our player gameobject can move.

profile
Growing Game Dev

0개의 댓글