커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
제가 뭘 놓친건지 먹이가 강아지 위치를 안따라가요ㅠㅠ
undefined주차
북마크
나*미
댓글
5
추천
0
조회수
15
조회수
15
답변 완료

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

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


중간에 Food객체를 지웠다가 다시 만들었더니 이러는 것 같아요 GameManager에도 새로운 객체를 잘 집어넣었는데 안되네요ㅠㅠ



스파르타 즉문즉답




// GameManager

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.SceneManagement;


public class StartBtn : MonoBehaviour

{

  // Start is called before the first frame update

  void Start()

  {

     

  }


  // Update is called once per frame

  void Update()

  {

     

  }


  public void GameStart()

  {

    SceneManager.LoadScene("MainScene");

  }

}








// Dog

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Dog : MonoBehaviour

{

  // Start is called before the first frame update

  void Start()

  {

     

  }


  // Update is called once per frame

  void Update()

  {

    // 마우스가 움직이는 대로 강아지 움직이기

    Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);   // 마우스 위치 포착하기

    float x = mousePos.x;

    if (x >8.5f)

    {

      x = 8.5f;

    }

    if (x < -8.5f)

    {

      x = -8.5f;

    }

    transform.position = new Vector3(x, transform.position.y, 0);   // 강아지의 x좌표 위치만 마우스 따라가기, y는 원래위치

  }

}








// Food

using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class Food : MonoBehaviour

{

  // Start is called before the first frame update

  void Start()

  {

     

  }


  // Update is called once per frame

  void Update()

  {

    transform.position += new Vector3(0, 0.5f, 0);  // 사료를 일정한 속도로 쏴줌

    if (transform.position.y > 26.0f){

      Destroy(gameObject);  // Destroy는 객체를 없애주는 함수

    }

  }

}





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