Пример #1
0
    void SwitchPart(int partIndex)
    {
        if (currentPartIndex == partIndex || partIndex >= partPrefabs.Length)
        {
            return;
        }

        if (cursor != null)
        {
            Destroy(cursor.gameObject);
        }

        if (placingPart)
        {
            currentHitPart = null;
            placingPart    = false;
        }

        currentPartIndex = partIndex;

        cursor = GameObject.Instantiate <AttachablePart> (partPrefabs [currentPartIndex]);

        cursor.Initialize(true);

        List <Renderer> renderers = cursor.GetRenderers();

        for (int i = 0; i < renderers.Count; i++)
        {
            renderers [i].material = cursorMaterial;
        }

        cursor.SetCollidersEnabled(false);

        partSelectionUI.HighlightText(currentPartIndex);
    }
Пример #2
0
    // Update is called once per frame
    void Update()
    {
        CheckInput();

        if (placingPart)
        {
            if (PlayerController.instance.gameStarted)
            {
                Destroy(cursor.gameObject);
                cursor         = null;
                currentHitPart = null;
                placingPart    = false;
            }
            else
            {
                if (Input.GetKey(KeyCode.Q))
                {
                    cursor.transform.RotateAround(cursor.transform.position, cursor.transform.forward, -rotationSpeed * Time.deltaTime);
                }
                else if (Input.GetKey(KeyCode.E))
                {
                    cursor.transform.RotateAround(cursor.transform.position, cursor.transform.forward, rotationSpeed * Time.deltaTime);
                }
            }
        }

        if (!PlayerController.instance.gameStarted)
        {
            if (!placingPart)
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit, 1000f, layerMask.value, QueryTriggerInteraction.Ignore))
                {
                    Debug.DrawLine(transform.position, hit.point, Color.red, 3.0f);

                    currentHitPart = hit.collider.GetComponent <AttachablePart> ();
                    if (currentHitPart == null)
                    {
                        currentHitPart = hit.collider.transform.parent.GetComponent <AttachablePart> ();
                    }

                    if (currentHitPart != null)
                    {
                        cursor.gameObject.SetActive(true);
                        cursor.transform.position = hit.point;
                        cursor.transform.forward  = hit.normal;

                        if (Input.GetMouseButtonDown(0))
                        {
                            placingPart = true;
                        }
                    }
                }
                else
                {
                    cursor.gameObject.SetActive(false);
                }
            }
            else if (placingPart)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    AttachablePart newPart = GameObject.Instantiate <AttachablePart> (partPrefabs[currentPartIndex]);
                    newPart.transform.position = cursor.transform.position;
                    newPart.transform.rotation = cursor.transform.rotation;

                    newPart.Initialize(false);

                    newPart.SetupJoint(currentHitPart);

                    currentHitPart = null;
                    placingPart    = false;
                }
            }
        }
    }