인프런 커뮤니티 질문&답변
스크립트 오류 관련
작성
·
286
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;
}
}
스크립트에 문제 있는 부분 확인 부탁드립니다
퀴즈
Unity에서 플레이어의 물리적인 움직임(중력, 충돌)을 제어하기 위해 주로 어떤 컴포넌트들이 필요할까요?
Animator와 Sprite Renderer
Rigidbody 2D와 Collider 2D
Transform과 Camera
Script와 Audio Source
답변 2
0
네임스페이스가 없다고하네요.
처음에 스크립트만들면 맨윗줄에
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
이부분이 지워지지 않았는지 확인해보세요.
0





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