0905 배운 내용

null·2023년 9월 25일

Unity Study

목록 보기
3/60
using System.Collections;

using System.Collections.Generic;

using Unity.VisualScripting;

using UnityEngine;

{

    // 번거로운 방식

    /*

    public int IDLE = 0;

    public int MOVE = 1;

    public int ATTACK = 2;

    public int HIT = 3;

    public int DEATH = 4;

    */



    //열거형식(enum)

    // 상수의 값은 오탈자(실수) 발생

    // 열거형식을 통해 해결 가능

    // 여러개의 상수 선언보다 열거형식이 낫다



    public enum PlayerState    {Idle, Move, Attack, Hit, Death}



    public PlayerState myPlayer = PlayerState.Idle; //내 상태



    public int Spider_Hp = 100;





    // Start is called before the first frame update

    void Start()

    {



    }



    private void OnMouseDown()

    {



        Spider_Hp = Spider_Hp - 10;

        print("거미에게 10 데미지!");



        /*

        myPlayer = PlayerState.Attack;

        if (myPlayer == PlayerState.Attack)

        {

            print("공격 상태");

            transform.Translate(0, 0, 1f);

        }

        else

        {

            print("else");

            transform.Translate(0, 10f, 0);

        }

        */

    }



    private void OnCollisionEnter(Collision collision)

    {



    }



    private void OnTriggerEnter(Collider other)

    {



        if (other.name == "Box")

        //if (other.tag == "Box")

        {

            Spider_Hp = Spider_Hp - 50;

            other.GetComponent<Renderer>().material.color = Color.red;

            other.GetComponent<Collider>().isTrigger = false;

            Destroy(other.gameObject, 3.0f);

            print("거미가 상자 파괴!");

        }

    }





    // Update is called once per frame

    void Update()

    {

        if (gameObject.tag == "Enemy")

        {

            print("적 태그");

            {

                if (myPlayer == PlayerState.Idle)

                {

                    print("대기 중");

                }

            }

        }

        if (myPlayer == PlayerState.Move)

        {

            print("이동 중");

        }

        if (myPlayer == PlayerState.Attack)

        {

            print("공격 중");

        }

        if (myPlayer == PlayerState.Hit)

        {

            print("피격 중");

        }

        if (myPlayer == PlayerState.Death)

        {

            bool enemyAlive = false;

            Destroy(gameObject, 3.0f);

            print("사망 상태");

        }

        if (Spider_Hp <= 50)

        {

            myPlayer = PlayerState.Hit;

            print("거미 중상");

        }

        if (Spider_Hp <= 0)

        {

            myPlayer = PlayerState.Death;

            print("거미 사망");

        }

    }

}

0개의 댓글