반응형

 

그림을 나타낼 큐브를 만들고 애니메이션을 주는 작업을 하겠습니다

먼저 GameObject에서  Cube을 생성합니다

 

 

cardGame_texture.unitypackage
3.18MB

Resources 폴더에 그림파일을 임포트 합니다

 

 

 

 

Materials 폴더에 Material을 생성하고 이름을 card_back으로 하고 Card 오브젝트 에 메터리얼을 드래그하여 붙이고 메터리얼 Shader를 Lagacy Shaders -> Transparent -> Diffuse를 선택합니다

그리고 그림을  Resources 파일에 있는 back 5를 붙입니다

 

Card 오브젝트에 붙일 CardCtrl 스크립트를 생성하여 스크립트 작업을 합니다

 

CardCtrl 스크립트 작성

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

public class CardCtrl : MonoBehaviour
{
    //이미지 번호
    int imgNum = 1;

    //카드 뒷면 이미지 번호
    int backNum = 1;

    // 오픈된 카드의 판별여부 
    bool isOpen = false;

    Animator anim;


    // Start is called before the first frame update
    void Start()
    {
        anim = GetComponent<Animator>();
;
    }


    //카드 앞면을 이미지을 가지고 온다
    void ShowImage()
    {
        transform.GetComponent<Renderer>().material.mainTexture = Resources.Load("card" + imgNum) as Texture2D;
    }


    //카드 뒷면 이미지을 가지고 온다
    void HideImage()
    {
        transform.GetComponent<Renderer>().material.mainTexture = Resources.Load("back" + backNum) as Texture2D;
    }
}

 

 

 

 

작성한 스크립트를 Card 오브젝트에 붙입니다

 

메인 카메라를 선택하고 Transform을 그림과 같이 바꿉니다

 

 

 

 

BackManager 자식으로 Camera 오브젝트를 생성하여 이름을 MaskCamera 라하고  Transform을 아래 그림과 같이 바꿉니다

 

 

Card 오브젝트를 선택하고  Window -> Animation -> Animation을 선택합니다

 

aniOpen  애니메이션을 생성하고 붉은 단추를 누르고 0 프레임에  Rotation Z값을 0을 줍니다

 

aniOpen  애니메이션을  30 프레임에  Rotation Z값을 -180을 줍니다

 

 

 

aniOpen 애니메이션에 15 프레임 정도에 Add event를 넣고 ShowImage() 함수를 연결합니다

 

aniOpen 애니메이션에 0 프레임에 Add event를 넣고 HideImage() 함수를 연결합니다

 

 

그리고  aniClose 애니메이션을 생성하고 빨간 단추를 누르고 0 프레임에 Rotation Z값을 -180 을 주고 30프레임에 Rotation Z값을 0을 줍니다

 

 

 

aniClose 애니메이션을 선택하고 0프레임에 Add event를 추가하고 ShowImage() 함수를 연결합니다

 

aniClose 애니메이션을 선택하고 15 프레임에 Add event를 추가하고 HideImage() 함수를 연결합니다

 

aniClose, aniOpen 애니메이션의  Loop Time을 체크 해제합니다

 

 

 

Animator에 들어가서 Create State -> empty를 생성하여  Set as layer Default state를 선택합니다

 

 

Resources 폴더에 Prefab 폴더를 생성하고 Card 오브젝트를 드래그하여 프리 팹을 만듭니다

 

 

하이라키에 있는 Card 오브젝트는 삭제합니다

반응형

+ Recent posts