커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
3주차 2강
게임 개발이 처음이어도 쉽게 배우는 모바일 게임 개발 v0
3주차
북마크
조*신
댓글
7
추천
0
조회수
11
조회수
11
답변 완료

* 겪고 있는 문제 상황을 최대한 자세하게 작성해주세요.

* 문제 해결을 위해 어떤 시도를 해보았는지 구체적으로 함께 알려주세요.


Dog가 움직일 때 쭉쭉 이동하지를 않습니다.



https://drive.google.com/file/d/1InY4pZsVpIY8AliMcjmvDnJnLLwz2j6q/view?usp=drive_link

(문제의 영상 링크입니다.)

스파르타 즉문즉답

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Dog : MonoBehaviour

{

  public GameObject food;

  // Start is called before the first frame update

  void Start()

  {

    InvokeRepeating("MakeFood", 0f, 0.5f);

  }

  private void Update()

  {

    Vector2 mousePos = Camera.main.ScreenToViewportPoint(Input.mousePosition);

    float x = mousePos.x;

    if (x > 8.5f)

    {

      x = 8.5f;

    }

    if(x < -8.5f)

    {

      x = -8.5f;

    }

    transform.position = new Vector2(mousePos.x, transform.position.y);

  }


  // Update is called once per frame

  void MakeFood()

  {

    float x = transform.position.x;

    float y = transform.position.y * 2.0f;

    Instantiate(food, new Vector2(x, y), Quaternion.identity);

  }

}




작성한 코드 및 에러 메세지





취소
 공유
취소
댓글 0
댓글 알림
나의얼굴