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

고양이가 죽기도 전에 옆으로 이동하는데

안 죽었을때 내려오는 조건문도 같이 발동이 되어서 대각선으로 내려오면서 화면 밖으로 나갑니다


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


public class Cat : MonoBehaviour
{


    public RectTransform front;
    public GameObject HungryCat;
    public GameObject FullCat;


    float full = 5.0f;
    float enegry = 0.0f;






    // Start is called before the first frame update
    void Start()
    {


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


    }


    // Update is called once per frame
    void Update()
    {


        if (transform.position.x < -10.0f)
        {
            Destroy(gameObject);
        }
        if (transform.position.x > 10.0f)
        {
            Destroy(gameObject);
        }






        if (enegry < full)
        {
            transform.position += Vector3.down * 0.05f;


            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;
                }
            }




        }












    }


        private void OnTriggerEnter2D(Collider2D collision)
        {
            if (collision.gameObject.CompareTag("Food"))
            {
                if (enegry < full)
                {
                    enegry += 1.0f;
                    front.localScale = new Vector3(enegry / full, 1.0f, 1.0f);
                    Destroy(collision.gameObject);
                }
                if (enegry == 5.0f)
                {
                    HungryCat.SetActive(false);
                    FullCat.SetActive(true);
                }


            }
        }


}










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