작성
·
126
·
수정됨
0
All compiler errors have to be fixed before you can enter playmode!
UnityEditor.SceneView:ShowCompileErrorNotification ()
찾아보니까 스크립트에서 잘못 작성해서 나온 에러 라는데 어디가 틀린것인지 모르겠어요..
도와주세요
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BirdJump : MonoBehaviour
{
Rigidbody2D rb;
public float jumpPower;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
Debug.Log("start");
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0)){ // 마우스를 클릭 했을 때
rb.velocity = Vector2.up * jumpPower; // (0, 1) , vector2 = x, y
}
private void OnCollisionEnter2D(Collision2D other)
{
SceneManager.LoadScene("GameOverScane");
}
}
}
답변 1
0
안녕하세요, 인프런 AI 인턴입니다.
w2213님, 스크립트에 작성된 코드를 확인해보니, OnCollisionEnter2D
메소드가 Update
메소드 내에 정의되어 있는 것이 문제입니다. OnCollisionEnter2D
메소드는 Update
메소드 밖으로 이동시켜야 합니다. 또한 SceneManager.LoadScene
을 사용하기 위해서는 using UnityEngine.SceneManagement;
을 추가해야 합니다. 아래와 같이 수정하면 에러를 해결하실 수 있습니다.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement; // 이 부분을 추가하세요.
public class BirdJump : MonoBehaviour
{
Rigidbody2D rb;
public float jumpPower;
// Start is called before the first frame update
void Start()
{
rb = GetComponent<Rigidbody2D>();
Debug.Log("start");
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0)){ // 마우스를 클릭 했을 때
rb.velocity = Vector2.up * jumpPower; // (0, 1) , vector2 = x, y
}
}
// OnCollisionEnter2D는 Update 메소드 밖에 위치해야 합니다.
private void OnCollisionEnter2D(Collision2D other)
{
SceneManager.LoadScene("GameOverScene");
}
}
이렇게 수정 후 스크립트를 저장하고 Unity 에디터로 돌아가시면, 이제 Playmode에 들어가실 수 있을 겁니다.