Esempio n. 1
0
    private IEnumerator FollowFinger()
    {
        currentCam = planeMan.GiveCurrentCam();
        bool perspectivCam = planeMan.PerspectiveCam();

        grabbed = true;
        Vector3    worldPoint;
        RaycastHit hit;

        while (grabbed)
        {
            Vector2 mouse = Input.mousePosition;
            if (perspectivCam)
            {
                worldPoint = currentCam.ScreenToWorldPoint(new Vector3(mouse.x, mouse.y, 250));
                if (Physics.Raycast(currentCam.transform.position, worldPoint, out hit, 10, ignoreMask))
                {
                    MapTile mapTile = hit.collider.gameObject.GetComponent <MapTile>();
                    if (mapTile != null)
                    {
                        if (mapTile.TileStatus == MapTile.BuildStatus.Start && mapTile.IsBuildable)
                        {
                            landingAnim.SetTrigger("Prepare");
                            onStartapult = true;
                            planeOnField = mapTile;
                            SetItemsPosition(mapTile.transform.position);
                            gameObject.transform.rotation = mapTile.transform.rotation;
                        }
                        else
                        {
                            onStartapult = false;
                            planeOnField = null;
                            landingAnim.SetTrigger("Start");
                            SetItemsPosition(hit.point);
                        }
                    }
                    else
                    {
                        onStartapult = false;
                        planeOnField = null;
                        landingAnim.SetTrigger("Start");
                        SetItemsPosition(hit.point);
                    }
                }
                else
                {
                    ResetPlane();
                }
            }
            else
            {
                Ray ray = currentCam.ScreenPointToRay(new Vector3(mouse.x, mouse.y, 250));
                if (Physics.Raycast(ray.origin, currentCam.transform.forward, out hit, 10, ignoreMask))
                {
                    MapTile mapTile = hit.collider.gameObject.GetComponent <MapTile>();
                    if (mapTile != null)
                    {
                        if (mapTile.TileStatus == MapTile.BuildStatus.Start && mapTile.IsBuildable)
                        {
                            landingAnim.SetTrigger("Prepare");
                            onStartapult = true;
                            planeOnField = mapTile;
                            SetItemsPosition(mapTile.transform.position);
                            gameObject.transform.rotation = mapTile.transform.rotation;
                        }
                        else
                        {
                            onStartapult = false;
                            planeOnField = null;
                            landingAnim.SetTrigger("Start");
                            SetItemsPosition(hit.point);
                        }
                    }
                    else
                    {
                        onStartapult = false;
                        planeOnField = null;
                        landingAnim.SetTrigger("Start");
                        SetItemsPosition(hit.point);
                    }
                }
                else
                {
                    ResetPlane();
                }
            }
            yield return(null);
        }
    }