본문 바로가기
College Computer Science/VR AR MR

[Unity] 네모로직 3D

by 2den 2022. 2. 15.
728x90

Gameplay.cs

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

public class GamePlay : MonoBehaviour
{
    public Camera getCamera;
    private RaycastHit hit;
    private int death = 0;
    private int isover = 0;

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

    // Update is called once per frame
    void Update()
    {
        string objectName = null;

        if(Input.GetMouseButtonDown(0))
        {
            Ray ray = getCamera.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit))
            {
                objectName = hit.collider.gameObject.name;
                Debug.Log(objectName);
            }
        }

        if(objectName=="finish")
        {
            GameOver();
        }
        else if(objectName!=null)
        {
            GameObject selected = transform.Find(objectName).gameObject;
            Color present = selected.GetComponent<Renderer>().material.color;
            
            if (present == Color.blue)
            {
                selected.GetComponent<Renderer>().material.color = Color.white;
            }
            else if (present == Color.white)
            {
                selected.GetComponent<Renderer>().material.color = Color.gray;
            }
            else
            {
                selected.GetComponent<Renderer>().material.color = Color.blue;
            }
        }

        if(Input.GetKeyDown(KeyCode.Space))
        {
            death += 1;
            transform.Find("hint").gameObject.SetActive(true);
        }

        if(death>0 && death <=3)
        {
            transform.Find("Heart" + death.ToString()).gameObject.SetActive(false);
        }
        
        if(death>3)
        {
            isover = 1;
            GameOver();
        }

        if(Input.GetKeyUp(KeyCode.Space))
        {
            transform.Find("hint").gameObject.SetActive(false);
        }
    }

    void GameOver ()
    {
        Transform[] allcubes = GetComponentsInChildren<Transform>();
        foreach (Transform cubes in allcubes)
        {
            if (cubes.gameObject.name.Contains("Cube"))
            {
                cubes.gameObject.SetActive(false);
            }
        }

        if (isover == 1)
        {
            transform.Find("gameover").gameObject.SetActive(true);
        }

        GameObject redparent = transform.Find("redparent").gameObject;
        redparent.gameObject.SetActive(true);
        foreach (Transform red in redparent.transform)
        {
            red.gameObject.GetComponent<Renderer>().material.color = Color.red;
        }

        GameObject brownparent = transform.Find("brownparent").gameObject;
        brownparent.gameObject.SetActive(true);
        foreach (Transform brown in brownparent.transform)
        {
            brown.gameObject.GetComponent<Renderer>().material.color = new Color(0.4F, 0.2F, 0.0F);
        }

        GameObject blackparent = transform.Find("blackparent").gameObject;
        blackparent.gameObject.SetActive(true);
        foreach (Transform black in blackparent.transform)
        {
            black.gameObject.GetComponent<Renderer>().material.color = Color.black;
        }
    }
}

 

프로젝트 압축 파일 :

 

nonogram.zip

 

drive.google.com

(다운로드 후 사용 가능, 웹 상에 업로드 시 이 블로그 링크를 추가해주세요.)

 

 

시연 영상:

nonogram simulation.mp4
18.41MB

 

728x90

'College Computer Science > VR AR MR' 카테고리의 다른 글

[VR] BCI(Brain-Computer Interface)와 VR  (0) 2022.02.15
[Unity] 다이빙 게임 (팀프로젝트)  (0) 2022.02.15
[Unity] Roll a Ball  (0) 2022.02.15

댓글