강의

멘토링

커뮤니티

Inflearn コミュニティ Q&A

fineapplestudios のプロフィール画像
fineapplestudios

投稿した質問数

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

基本キャラクターの動き

Rigidbody 오류

作成

·

432

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

回答

回答を待っている質問です
最初の回答を残してください!
fineapplestudios のプロフィール画像
fineapplestudios

投稿した質問数

質問する