Exemple #1
0
    int WhichRegion()
    {
        int i;

        for (i = 0; i < transform.childCount; i++)
        {
            CameraRegion region  = transform.GetChild(i).gameObject.GetComponent <CameraRegion>();
            float        width   = region.Width;
            float        height  = region.Height;
            float        regionx = region.gameObject.transform.position.x;
            float        regiony = region.gameObject.transform.position.y;

            if ((x >= regionx - width) && (x < regionx + width) && (y >= regiony - height) && (y < regiony + height))
            {
                curWidth  = region.Width;
                curHeight = region.Height;
                curLeft   = regionx - width;
                curRight  = regionx + width;
                curUp     = regiony + height;
                curDown   = regiony - height;
                regionNum = i;
                curRegion = region;
                break;
            }
        }
        return(i);
    }
    void Update()
    {
        // which region is my target in (that's where I want look)
        Vector3 targetPos = objectToFollow.transform.position;

        // Which region is my part of?
        CameraRegion currentRegion = FindRegionForPoint(targetPos);

        if (currentRegion != null)
        {
            // put where I want it
            Bounds cameraBounds = Camera.main.GetWorldBounds();
            cameraBounds.center = new Vector3(targetPos.x, targetPos.y, cameraBounds.center.z);

            // nudge back if need be
            cameraBounds = FitWithinBoundsXY(cameraBounds, currentRegion.GetWorldBounds());

            Vector3 finalPos = new Vector3(cameraBounds.center.x, cameraBounds.center.y, Camera.main.transform.position.z);
            Camera.main.transform.position = finalPos;
        }
        else
        {
            // don't do anything... might want to center palyer.. or kill player... yaknow.. whatever...
        }
    }
Exemple #3
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.CompareTag("Region"))
     {
         region = other.GetComponent <CameraRegion>();
         region.ChangeRegion();
     }
 }
Exemple #4
0
    // Use this for initialization
    void Start()
    {
        controller = GetComponent <Rigidbody>();
        region     = GetComponent <CameraRegion>();

        Cursor.lockState = CursorLockMode.Locked;

        rotateActive = true;
    }
    CameraRegion FindRegionForPoint(Vector2 position)
    {
        for (int i = 0; i < cameraRegions.Length; ++i)
        {
            CameraRegion region = cameraRegions[i];
            Bounds       b      = region.GetWorldBounds();

            if ((position.x >= b.min.x) &&
                (position.x <= b.max.x) &&
                (position.y >= b.min.y) &&
                (position.y <= b.max.y))
            {
                return(region);
            }
        }

        return(null);
    }