inflearn logo
강의

講義

知識共有

[Unity 3D] FPSサバイバルディフェンス

基本キャラクターの動き

Rigidbody 오류

443

seunghyunpyo

投稿した質問数 1

0

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    [SerializeField]
    private float walkSpeed;

    [SerializeField]
    private Rigidbody myRigid;

    // Start is called before the first frame update
    void Start()
    {
        myRigid = GetComponent<Rigidbody>();
    }

    // Update is called once per frame
    void Update()
    {


        Move();


    }
    private void Move()
    {

        float _moveDirX = Input.GetAxisRaw("Horizontal");
        float _moveDirZ = Input.GetAxisRaw("Vertical");

        Vector3 _moveHorizontal = transform.right * _moveDirX;
        Vector3 _moveVertical = transform.forward * _moveDirZ;

        Vector3 _velocity = (_moveHorizontal + _moveVertical).normalized * walkSpeed;
        myRigid.MovePosition(transform.position + _velocity * Time.deltaTime);
    }

}

이렇게 작성했는데 MissingComponentException: There is no 'Rigidbody' attached to the "Player" game object, but a script is trying to access it. 오류가 나요 뭐가문제죠?

unity

回答 0

코드 관련 질문

0

9

1

섹션7 수업자료 업로드 부탁드립니다.

0

18

2

Dictionary Key를 int에서 string으로 변경한 이유에 대한 문의

0

16

1

UI 기능 관련 질문이 있습니다!

0

36

2

03-01 (16. CharacterController)

0

29

2

TLS 질문드립니다.

0

43

2

Task 구현 28:36 Equals 에서 잘 모르는 부분이 있습니다.

0

26

2

SpinLock과 컨텍스트스위칭에 대해 질문 남겨요.

0

46

2

픽셀 좌표 스크린 좌표

0

32

0

Locomotion랑 Turn 이 꼭 부모 자식 관계일 필요가 있나요?

0

23

1

LobbyUIController의 백키가 사라졌는데 왜그런건가요?

0

40

2

무조건 타이틀 씬부터 시작해야하나요?

0

39

1

BaseUI, UIManager

0

50

3

프로젝트 완성본 문의

0

40

2

Unity Span

0

75

2

씬 배치 구조에서 Addressables를 어떻게 적용해야 하는지 궁금합니다.

0

53

1

트랜지션 추가가 불가능하여 여쭤봅니다

0

310

0

처음 playerscript 어디가 틀렸나요?

1

333

1

Asset 파일링크

0

334

1

너무 작동이 안됩니다

0

215

0

에셋 안넣어져요

0

371

3

기본무기를 맨손으로 하고싶어요!

0

310

0

특정 아이템이 인벤토리에 존재하면 특정 행동을 할 수 있게 적용 하는 방법이 있나요?

0

229

0

중간에 앉기 기능이 있는데 컨트롤키를 누르고 있을때만 앉아 있을수 없나요?

0

307

1