모각소 _ 0810

윰이다·2022년 8월 10일
0

여번 시간에는 랩실 유니티 개발을 하였다.

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

public class ConveyBeltManager : MonoBehaviour
{
    public float speed;
    public Rigidbody rigidbody;
   // public GameObject CUBE;
    private bool stop = false;
    public List<GameObject> list;
    private int i=0;
    public GameObject CurrentModel;
    public int Limit_Num=5;

    private bool first = true;
    private Vector3 MugPos = new Vector3(0, 0.51f, -1.849f);
    private Vector3 IllusionPos = new Vector3(0, 0.508f, -1.64f);
    private Vector3 GuitarPos = new Vector3(0, 0.792f, -1.849f);
    private Vector3 Circle2x2Pos = new Vector3(-0.605f, 0.474f, -1.729f);
    private Vector3 Cube4xPos = new Vector3(0, 0.597f, -1.849f);
    private Vector3 DogPos = new Vector3(0, 0.8f, -1.849f);


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

    // Update is called once per frame
    void Update()
    {
        if(Input.GetKeyDown(KeyCode.W))
        {
            Debug.Log("W!");
            CheckButton();
        }
        if(Input.GetKeyDown(KeyCode.S))
        {
            Debug.Log("S!");
            PassButton();
        }
    }
    
    void FixedUpdate()
    {
        
        if(!stop)
        {
            rigidbody.position -= transform.forward * speed * Time.deltaTime;
            rigidbody.MovePosition (rigidbody.position + transform.forward * speed * Time.deltaTime);
        }
        StopPosition();
    }

    void StopPosition()
    {
        if(CurrentModel.transform.position.z>=0 && first)
        {
            stop = true;
            first = false;
            Debug.Log(CurrentModel.transform.eulerAngles);
            Debug.Log(CurrentModel.transform.rotation);
        }
    }

    void CheckButton()
    {
        Debug.Log("local Euler: " + CurrentModel.transform.localEulerAngles);
        Debug.Log("Euler: " + CurrentModel.transform.eulerAngles);
        Debug.Log("Quaternion: " + CurrentModel.transform.rotation);

        Debug.Log(CurrentModel.name);
        //Mug
        if(CurrentModel.name == "Mug" && Mathf.Round(CurrentModel.transform.eulerAngles.y) == 90)
        {
            //맞춤 0
            Debug.Log("TRUE");
            if(i<Limit_Num)
            {
            i++;
            CurrentModel = Instantiate(list[i],InstantiatePos(list[i]), Quaternion.identity);
            stop = false;
            first = true;
            }
            else if(i==Limit_Num)
            {
                stop = false;
            }
        }
        
        //Guitar
        else if(CurrentModel.name == "Guitar" && Mathf.Round(CurrentModel.transform.localEulerAngles.z) == 45)
        {
            //맞춤 0
            Debug.Log("TRUE");
            if(i<Limit_Num)
            {
            i++;
            CurrentModel = Instantiate(list[i],InstantiatePos(list[i]), Quaternion.identity);
            stop = false;
            first = true;
            }
            else if(i==Limit_Num)
            {
                stop = false;
            }
        }
        
        //Dog
        else if(CurrentModel.name == "Dog" && Mathf.Round(CurrentModel.transform.localEulerAngles.z) == 45)
        {
            //맞춤 0
            Debug.Log("TRUE");
            if(i<Limit_Num)
            {
            i++;
            CurrentModel = Instantiate(list[i],InstantiatePos(list[i]), Quaternion.identity);
            stop = false;
            first = true;
            }
            else if(i==Limit_Num)
            {
                stop = false;
            }
        }

        //4xCube    
        else if(CurrentModel.name == "4xCube" && Mathf.Round(CurrentModel.transform.localEulerAngles.z) == 45)
        {
            //맞춤 0
            Debug.Log("TRUE");
            if(i<Limit_Num)
            {
            i++;
            CurrentModel = Instantiate(list[i],InstantiatePos(list[i]), Quaternion.identity);
            CurrentModel.name = list[i].name;
            stop = false;
            first = true;
            }
            else if(i==Limit_Num)
            {
                stop = false;
            }
        }
        else{
            Debug.Log("FALSE");
            return;
        }
    }


    void PassButton()
    {
        if(CurrentModel.name == "Illusion(Clone)" || CurrentModel.name == "Circle2x2")
        {
            //맞춤 0
            Debug.Log("TRUE");
            if(i<Limit_Num)
            {
            i++;
            CurrentModel = Instantiate(list[i],InstantiatePos(list[i]), Quaternion.identity);
            CurrentModel.name = list[i].name;
            stop = false;
            first = true;
            }
        }
        else{
            Debug.Log("FALSE");
            return;
        }
    }    

    Vector3 InstantiatePos(GameObject nextOne )
    {
        if(nextOne.name == "Mug")
            return MugPos;
        else if (nextOne.name == "Illusion")
            return IllusionPos;
        else if (nextOne.name == "Guitar")
            return GuitarPos;
        else if (nextOne.name == "Circle2x2")
            return Circle2x2Pos;        
        else if (nextOne.name == "4xCube")
            return Cube4xPos;
        else if (nextOne.name == "Dog")
            return DogPos;
        else 
            return new Vector3(0,0,0);
    }
}

코드를 보면 알 수 있듯이 개연성이 없다 ..ㅎ...
리스트를 짜서 깔끔한 코드를 완성하고 싶었으나 그러하지 못했다.

0개의 댓글