대외활동/starters 부트캠프 feat.웅진씽크빅

유데미 스타터스 취업 부트캠프 유니티 1기 14주차 학습 일지

Heeyeon Choi 2022. 9. 25. 23:47
728x90
728x90

머니모아모아 Game

- 키티가 2분동안 달리면서 돈을 모으는 게임을 제작해봤습니다^^
- 아래 인벤토리창에 먹은 돈, 음료수, 적 개수가 표시 됩니다.
- 오른쪽 상단에 하트를 모두 소진 후, 적과 또 닿을 경우 게임 오버 됩니다.
- 적과 닿으면 하트 한 개 소진, 음료수를 먹으면 하트 한 개 추가됩니다.
- 키티가 뛰어다닐 때 파티클 효과를 넣어주었습니다.
- 시선을 2d 느낌으로 카메라를 설정해주었습니다.

 

 

  • 기획
    1. 체력 → 하트 3개
      1. 음료수를 통해 채울 수 있음
      2. 적과 부딪히면 체력이 줄어듬
      1. 1000원을 모을 수 있음
    2. 장애물
      1. 책상, 의자, 구름, 나무는 장애물로 넘거나 피해야 함
    3. 게임 오버
      1. 체력을 모두 소진했을 시 (하트가 0개 일 시)
    4. 게임 클리어
      1. 타이머 안에 돈을 모으는 것

 

<수정할 사항>

1. 타이머가 5초 남았을 때 효과음이 제대로 작동하지 않음

2. 게임 시작시 어둡게 시작함

 

 

<PlayerMove 코드>

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerMove : MonoBehaviour
{
    public Animator anicon;
    public Rigidbody rb;
    AudioManager audioManager;

    public float moveSpd = 300f;
    public float boostSpd = 600f;
    public float jumpPower = 7f;
    public float rayDis = 0.7f;
    public Transform rayPoint;
    public bool isGrounded = false;
    int jumpCnt = 0;
    AudioManager am;


    //플레이어의 체력(하트) 변수
    public static int health=3;
    //돈 변수
    public static int money = 0;
    //게임 오버 캔버스
    public GameObject gameOver;
    //인벤토리 캔버스
    public GameObject invenCanvas;
    void Start()
    {
        audioManager = FindObjectOfType<AudioManager>();

        anicon = GetComponent<Animator>();
    }

  
    void Update()
    {
       
        Jump();
        
    }

    private void Jump()
    {
        if (isGrounded)
        {
            if (jumpCnt > 0)
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    rb.AddForce(new Vector3(0, 1, 0) * jumpPower, ForceMode.Impulse);
              
                    anicon.SetBool("jump", true);
                    anicon.SetBool("run", false);

                    jumpCnt--;
                }
            }
        }
    }

 

    private void OnCollisionEnter(Collision collision)
    {
        //땅에 닿으면 점프할 수 있도록 설정
        if (collision.gameObject.tag == "ground" || collision.gameObject.tag == "obstacle")
        {
            anicon.SetBool("jump", false);
            anicon.SetBool("run", true);

            isGrounded = true;
            Debug.Log("--------------땅이거나 장애물이다 나는---------------- ");
            jumpCnt = 2;
        }

    }

    //물건들과 부딪혔을 때, 각각의 아이템 효과 주기
    private void OnTriggerEnter(Collider other)
    {
        //컵을 먹으면 체력이 증가하도록 설정
        if (other.gameObject.tag == "cup")
        {
            Debug.Log("%%%%%%%%%%%%%컵이다 나는%%%%%%%%%%%%%%%%%%%%%%%%");
            if (health < 3)
            {
                health += 1;
            }
           
            Destroy(other.gameObject);

        }

        //1000원 먹으면 돈이 저장
        if (other.gameObject.tag == "1000")
        {
            Debug.Log("@@@@@@@@@@@@@@@@@@@@@@돈 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
            money += 1;
            audioManager.audioSource1.Play();


            Destroy(other.gameObject);

        }

        /*//장애물은 아무 효과 없음
        if (other.gameObject.tag == "obstacle")
        {
            Debug.Log(")))))))))))))))))))장애물이다 나는(((((((((((((((((((((((((");
            

        }*/

        //적이랑 부딪히면 체력이 줄어듬
        if (other.gameObject.tag == "enemy")
        {
            Debug.Log("***********************적이랑 부딪힘**********************************");

            if (health > 0)
            {
                health -= 1;
            }else if (health <= 0)
            {
                gameOver.SetActive(true);
                invenCanvas.SetActive(false);
            }
        }
    }



}

 

 

 

 

——————————————————————————

유데미코리아 바로가기 : https://bit.ly/3b8JGeD

본 포스팅은 유데미-웅진씽크빅 취업 부트캠프 유니티 1기 과정 후기로 작성되었습니다.

728x90