커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
해적 고양이 만들기 질문
게임개발 종합반 v0
3주차
북마크
김*현
댓글
11
추천
0
조회수
16
조회수
16
답변 완료

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

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


이전 문의 이후 해적 고양이 만들기 진행하였는데, 4레벨이 되어도 해적 고양이가 나타나지 않음



보고 계신 화면 전체를

스파르타 즉문즉답


스파르타 즉문즉답

캡처해 주시면, 튜터님들이 빠르게 상황을 이해할 수 있어요.




작성한 코드 및 에러 메세지

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Unity.UI;
using UnityEngine.UI;
using UnityEditor.Experimental.GraphView;


public class GameManager : MonoBehaviour
{
    public static GameManager Instance;


    public GameObject normalCat;
    public GameObject fatCat;
    public GameObject pirateCat;
    public GameObject retryBtn;


    public RectTransform levelFront;
    public Text levelTxt;


    int level = 0;
    int score = 0;
    private void Awake()
    {
        if(Instance == null)
        {
            if(Instance == null)
            {
                Instance = this;
            }
            Application.targetFrameRate = 60;
        }
    }
    void Start()
    {
        InvokeRepeating("MakeCat", 0f, 1f);
    }


    void Update()
    {
        
    }
    void MakeCat()
    {
        Instantiate(normalCat);


        // lv.1 20% 확률로 고양이를 더 생성해준다.
        if(level == 1)
        {
            int p = Random.Range(0, 10);
            if(p < 2) Instantiate(normalCat);
        }
        // lv.2 50% 확률로 고양이를 더 생성해준다.
        else if(level == 2)
        {
            int p = Random.Range(0, 10);
            if (p < 5) Instantiate(normalCat);
        }
        // lv.3 뚱뚱한 고양이를 생성해준다.
        else if (level >= 3)
        {
            int p = Random.Range(0, 10);
            Instantiate(fatCat);
        }
        // lv.4 해적 고양이를 생성해준다.
        else if (level >= 4)
        {
            Debug.Log("냐용");
            int p = Random.Range(0, 10);
            Instantiate(pirateCat);
        }


    }


    public void GameOver()
    {
        retryBtn.SetActive(true);
    }


    public void AddScore()
    {
        score++;
        level = score / 5;
        levelTxt.text = level.ToString();
        levelFront.localScale = new Vector3((score - level * 5) / 5.0f, 1f, 1f);
    }
}


GameManager.cs

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class Cat : MonoBehaviour
{


    public GameObject hungryCat;
    public GameObject fullCat;


    public RectTransform front;


    public int type;


    float full = 5.0f;
    float energy = 0.0f;
    float speed = 0.05f;


    bool isFull = false;




    void Start()
    {
        float x = Random.Range(-9.0f, 9.0f);
        float y = 30.0f;
        transform.position = new Vector2(x, 30f);


        if (type == 1)
        {
            speed = 0.05f;
            full = 5f;
        }
        else if (type == 2)
        {
            speed = 0.02f;
            full = 10f;
        }
        else if (type == 3)
        {
            speed = 0.1f;
            full = 5f;
        }
    }




    void Update()
    {
        if(energy < full)
        {
            transform.position += Vector3.down * speed;
            if(transform.position.y < -16.0f)
            {
                GameManager.Instance.GameOver();
            }
        }
        else
        {
            if(transform.position.x > 0)
            {
                transform.position += Vector3.right * 0.05f;
            }
            else
            {
                transform.position += Vector3.left * 0.05f;
            }
            Destroy(gameObject, 3.0f);
        }
 
    }


    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.CompareTag("Food"))
        {
            if(energy < full)
            {
                energy += 1.0f;
                front.localScale = new Vector3(energy / full, 1.0f, 1.0f);
                Destroy(collision.gameObject);




                if (type == 1 & energy == 5 | type == 2 & energy == 10 | type == 3 & energy == 5)
                {
                    if (!isFull)
                    {
                        isFull = true;                                      // 방어 로직
                        hungryCat.SetActive(false);
                        fullCat.SetActive(true);
                        Destroy(gameObject, 3.0f);
                        GameManager.Instance.AddScore();
                    }


                }
            }


        }
    }
}


Cat.cs


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