강의

멘토링

커뮤니티

Inflearn Community Q&A

dohap991030's profile image
dohap991030

asked

Creating a Katana ZERO Style Game with Unity and C# (Basic Edition)

Player Movement

스크립트 오류 관련

Written on

·

283

0

public class Player : MonoBehaviour

{

    public float speed = 5;

    public float jumpUp = 1;

    public Vector3 direction;

 

    Animator pAnimator;

    Rigidbody2D pRig2D;

    SpriteRenderer sp;

 

    // Start is called before the first frame update

    void Start()

    {

        pAnimator = GetComponent<Animator>();

        pRig2D = GetComponent<Rididbody2D>();

        direction = Vector2.zero;

        sp = GetComponenet<SpriteRenderer>();

    }

 

    void Keyinput()

    {

        direction.x = Input.GetAxisRaw("Horizontal"); // left -1 right +1

 

        if (direction.x < 0)

        {

            // left

            sp.flipX = true;

 

        }

 

        else if (direction.x > 0)

        {

            // right

            sp.flipX = false;

        }

 

        else if (direction.x == 0)

        {

            

        }

    }

 

    // Update is called once per frame

    void Update()

    {

        Keyinput();

        Move();

    }

 

    public void Move()

    {

        transform.position += direction * speed * Time.deltaTime;

    }

}

 

스크립트에 문제 있는 부분 확인 부탁드립니다

unityC#

Answer 2

0

cosart님의 프로필 이미지
cosart
Instructor

네임스페이스가 없다고하네요. 

 

처음에 스크립트만들면 맨윗줄에 

 

using System.Collections;

 

using System.Collections.Generic;

 

using UnityEngine;

 

 

 

이부분이 지워지지 않았는지 확인해보세요. 

 

 

0

cosart님의 프로필 이미지
cosart
Instructor

콘솔 에러 빨간색 캡쳐 해주실수있나요? 어디서 에러났나요?

dohap991030님의 프로필 이미지
dohap991030
Questioner

이렇게 뜹니다. 답변 감사합니다

cosart님의 프로필 이미지
cosart
Instructor

네임스페이스가 없다고하네요. 

처음에 스크립트만들면 맨윗줄에 

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

 

이부분이 지워지지 않았는지 확인해보세요. 

dohap991030님의 프로필 이미지
dohap991030
Questioner

집어넣었는데도 이렇게 뜨네요.. 여러 번 답변 감사합니다

cosart님의 프로필 이미지
cosart
Instructor

오류가달라져서 좀 잡힌거같은데 

마지막껀 오타같구요 틀린거확인하시고 

마지막 강의에 최종버젼프로젝트있으닌깐 Player.cs파일 한번 열어서 뭐가 다른지 확인해보세요. 

 

dohap991030's profile image
dohap991030

asked

Ask a question