강의

멘토링

커뮤니티

Inflearn Community Q&A

fineapplestudios's profile image
fineapplestudios

asked

[Unity 3D] FPS Survival Defense

Basic character movements

Rigidbody 오류

Written on

·

433

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

Answer

This question is waiting for answers
Be the first to answer!
fineapplestudios's profile image
fineapplestudios

asked

Ask a question