커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
3-6,숙제 fatcat이 나오지가 않습니다. 해적고양이는 한마리정도 나오는거같습니다
undefined주차
북마크
김*환
댓글
10
추천
0
조회수
47
조회수
47
답변 완료

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

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


fatcat 클론은 생성이 되는데 나오지가 않고 쌓이기만 합니다.

pirateCat도 레벨4에 한마리정도만 나오는데 바로 리트라이 버튼이 떠서 숙제 제출을 못하고있습니다 ㅠㅠ






GameManager


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;


public class GameManager : MonoBehaviour

{

   public GameObject dog;

   public GameObject food;

   public GameObject normalCat;

   public GameObject fatCat;

   public GameObject pireateCat;

   public GameObject retryBtn;

   public Text levelText;

   public GameObject levelFront;

   public static GameManager I;


   int level = 0;

   int cat = 0;


   void Awake()

  {

    I = this;

  }

  // Start is called before the first frame update

  void Start()

  {

    Time.timeScale = 1f;

    InvokeRepeating("makeFood", 0.0f, 0.15f);

    InvokeRepeating("makeCat",0.0f, 1f);

  }


  // Update is called once per frame

  void Update()

  {

     

  }


  void makeFood()

  {

    float x = dog.transform.position. x;

    float y = dog.transform.position. y + 2.0f;

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

  }


  void makeCat()

  {

    Instantiate(normalCat);


    if (level == 1)

    {

      float p = Random.Range(0, 10);

      if (p < 2) Instantiate(normalCat);

    }

    else if (level == 2)

    {

      float p = Random.Range(0, 10);

      if (p < 5) Instantiate(normalCat);

    }

    else if (level == 3)

    {

      float p = Random.Range(0, 10);

      if (p < 6) Instantiate(normalCat);

      Instantiate(fatCat);

    }

    else if (level >= 4)

    {

      float p = Random.Range(0, 10);

      if (p < 8) Instantiate(normalCat);

      Instantiate(fatCat);

      Instantiate(pireateCat);

    }

  }


  public void gameOver()

  {

    retryBtn.SetActive(true);

    Time.timeScale = 0.0f;

  }


  public void addCat()

  {

    cat += 1;

    level = cat / 5;


    levelText.text = level.ToString();

    levelFront.transform.localScale = new Vector3((cat - level * 5) / 5.0f, 1.0f, 1.0f);

  }

}





cat.cs


using System.Collections;

using System.Collections.Generic;

using UnityEngine;


public class cat : MonoBehaviour

{

  float full = 5f;

  float energy = 0f;

  bool isFull = false;

  public int type;

  // Start is called before the first frame update

  void Start()

  {

    float x = Random.Range(-8.5f, 8.5f);

    float y = 30f;


    if (type == 1)

    {

      full = 10f;

    }

    transform.position = new Vector3(x, y, 0);

  }


  // Update is called once per frame

  void Update()

  {

    if (energy < full)

    {

      if(type == 0)

      {

        transform.position += new Vector3(0.0f, -0.02f, 0.0f);

      }

      

      else if (type == 1)

      {

        transform.position += new Vector3(0.0f, -0.03f, 0.0f);

      }


      else if (type == 2)

      {

        transform.position += new Vector3(0, -0.1f, 0);

      }


      if (transform.position.y < -16.0f)

      {

        GameManager.I.gameOver();

      }

    }

    else

    {

      if (transform.position.x > 0)

      {

        transform.position += new Vector3(0.02f, 0.0f, 0.0f);

      }

      else

      {

        transform.position += new Vector3(-0.02f, 0.0f, 0.0f);

      }

      Destroy(gameObject, 3.0f);

    }

  }


  void OnTriggerEnter2D(Collider2D coll)

  {

    if (coll.gameObject.tag == "food")

    {

      if (energy < full)

      {

        energy += 1f;

        Destroy(coll.gameObject);

        gameObject.transform.Find("hungry/Canvas/front").transform.localScale = new Vector3(energy / full, 1.0f, 1.0f);

      }

      else

      {

        if (isFull == false)

        {

          GameManager.I.addCat();

          gameObject.transform.Find("hungry").gameObject.SetActive(false);

          gameObject.transform.Find("full").gameObject.SetActive(true);

          isFull = true;

        }     

      }

    }

  }

}


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