Esempio n. 1
0
    // Update is called once per frame
    void Update()
    {
        Ray        ray = Camera.main.ViewportPointToRay(new Vector3(.5f, .5f, 0));
        RaycastHit hit;

        if (IsEnabled)
        {
            if (Physics.Raycast(ray, out hit))
            {
                IsHitCubeSurfaces = (hit.transform.gameObject.tag == "placearea") ? true : false;

                if (hit.transform.gameObject.GetComponent <SurfaceTarget>() != null)
                {
                    lastSurfaceTarget = currSurfaceTarget;
                    currSurfaceTarget = hit.transform.gameObject.GetComponent <SurfaceTarget>();
                    lastActualTarget  = currActualTarget;
                    currActualTarget  = currSurfaceTarget.originTransform.GetComponent <CubeTarget>();
                }

                if (IsHitCubeSurfaces)
                {
                    if (IsBuildMode)
                    {
                        if (currSurfaceTarget != lastSurfaceTarget)
                        {
                            lastSurfaceTarget.SetRenderer(false);
                        }

                        currActualTarget.SetRenderer(true);
                        currSurfaceTarget.SetRenderer(true);
                        focusIndicator.transform.position = currSurfaceTarget.transform.position;
                        focusIndicator.transform.rotation = currSurfaceTarget.spawnTransform.rotation;
                    }
                    else
                    {
                        if (currActualTarget != lastActualTarget)
                        {
                            lastActualTarget.SetRenderer(true);
                        }

                        currActualTarget.SetRenderer(false);
                        focusIndicator.transform.position = currActualTarget.transform.position;
                        focusIndicator.transform.rotation = Quaternion.identity;
                    }
                }
                else
                {
                    currActualTarget.SetRenderer(true);
                    currSurfaceTarget.SetRenderer(false);
                }
            }
        }
    }