커뮤니티
포인트
쿠폰
내 강의실
국비 신청 내역
증명서
계정
로그아웃
학습 질문
개발 일지
나의 활동
답변 완료
3주차 fatcat의 hp바가 활성화되지 않습니다
undefined주차
북마크
김*진
댓글
3
추천
0
조회수
6
조회수
6
답변 완료

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

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


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;


  // Start is called before the first frame update

  void Start()

  {

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

    float y = 30f;

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


    if(type==1)

    {

      speed = 0.05f;

      full = 5f;

    }

    else if(type==2)

    {

      speed = 0.02f;

      full = 10f;

    }

  }


  // Update is called once per frame

  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*speed;

      }

      else

      {

        transform.position += Vector3.left*speed;

      }

    }

  }


  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 (energy == 5.0f)

        {

          if (isFull==false)

          {

            isFull = true;

            hungryCat.SetActive(false); ;

            fullCat.SetActive(true);

            Destroy(gameObject, 2.0f);

            GameManager.Instance.AddScore();

          }

        }

      }

    }

  }

}

cat.cs 코드입니다








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