강의

멘토링

커뮤니티

인프런 커뮤니티 질문&답변

seunghyunpyo님의 프로필 이미지
seunghyunpyo

작성한 질문수

[유니티 3D] FPS 서바이벌 디펜스

기본 캐릭터 움직임

Rigidbody 오류

작성

·

428

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. 오류가 나요 뭐가문제죠?

답변

답변을 기다리고 있는 질문이에요
첫번째 답변을 남겨보세요!
seunghyunpyo님의 프로필 이미지
seunghyunpyo

작성한 질문수

질문하기