public void CameraAdjust(Vector3 offSet, float zSize, bool need)
    {
        if (mainCamCon != null)
        {
            if (need && first) // only set the first as original to be reset
            {
                if (route11 != null)
                {
                    tempOffset = new Vector3(route11.camOffSetList[route11.camOffSetList.Length - 1].x, 0f, route11.camOffSetList[route11.camOffSetList.Length - 1].z);
                }

                if (route != null)
                {
                    tempOffset = new Vector3(route.camOffSetList[route.camOffSetList.Length - 1].x, 0f, route.camOffSetList[route.camOffSetList.Length - 1].z);
                }

                tempSize = mainCamCon.GetComponent <Camera>().orthographicSize;
                first    = false;
            }

            mainCamCon.offsetX = offSet.x;
            mainCamCon.offsetZ = offSet.z;
            if (zSize != 0)
            {
                mainCamCon.Zoom(zSize);
            }
        }
    }
 public void CameraAdjust()
 {
     if (mainCamCon != null)
     {
         tempOffset         = new Vector3(route11.camOffSetList[route11.camOffSetList.Length - 1].x, 0f, route11.camOffSetList[route11.camOffSetList.Length - 1].z);
         tempSize           = mainCamCon.GetComponent <Camera>().orthographicSize;
         mainCamCon.offsetX = cameraOffset.x;
         mainCamCon.offsetZ = cameraOffset.z;
         if (zoomSize != 0)
         {
             mainCamCon.Zoom(zoomSize);
         }
     }
 }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        monsters = GameObject.FindGameObjectsWithTag("Enemy");


        distance = new float[monsters.Length];

        if (distance.Length != 0)
        {
            //setup a temp destination for baby moving recovery. stable!
            if (!switched)
            {
                tempDes = GetComponent <MoveCon>().des;
            }

            //setup a temp camera propotity for camera recovery.
            if (!camSwitched)
            {
                mainCamCon = Camera.main.GetComponent <MainCamCon>();
                if (mainCamCon != null)
                {
                    camOffSetX  = mainCamCon.offsetX;
                    camOffSetZ  = mainCamCon.offsetZ;
                    camZoomSize = mainCamCon.GetComponent <Camera>().orthographicSize;
                }
            }


            for (int i = 0; i < monsters.Length; i++)
            {
                distance[i] = Vector2.Distance(new Vector2(transform.position.x, transform.position.z), new Vector2(monsters[i].transform.position.x, monsters[i].transform.position.z));
            }

            Transform closestMonster;
            float     minDistance;



            minDistance = Mathf.Min(distance);                         // closest distance

            if (tempID != System.Array.IndexOf(distance, minDistance)) //in case found closer enemy!
            {
                needChange = true;
            }

            closestMonster = monsters[System.Array.IndexOf(distance, minDistance)].transform; // the closest monster!!
            tempID         = System.Array.IndexOf(distance, minDistance);
            direction      = new Vector2(transform.position.x - closestMonster.position.x, transform.position.z - closestMonster.position.z);

            if (minDistance < alertRange)
            {
                if (!switched || needChange)
                {
                    direction = direction.normalized; // got a nomralized direction for baby alert moving
                                                      //switch mode
                    babyRandomAround.runAway     = true;
                    babyRandomAround.offsetX     = direction.x;
                    babyRandomAround.offsetZ     = direction.y;
                    babyRandomAround.enabled     = true;
                    GetComponent <MoveCon>().des = babyRandomAround.transform;// set baby's moving directon to random(alert mode)
                    sweatDrop.RepeatDrop(true);
                    switched   = true;
                    needChange = false;
                }
            }

            else if (minDistance > alertRange + 1)
            {
                if (switched)
                {
                    GetComponent <MoveCon>().des = tempDes; // if no close monster then nothing happened
                    sweatDrop.RepeatDrop(false);
                    babyRandomAround.enabled = false;
                    switched = false;
                }
            }

            //zoom camera when the enemy is close.

            if (minDistance < dangerRange)
            {
                if (!camSwitched)
                {
                    //set camera position
                    mainCamCon.offsetX = -direction.x / 2;
                    mainCamCon.offsetZ = -direction.y / 2;// only vector2 y=z
                    //zoom in

                    mainCamCon.Zoom(ZoomSize);


                    camSwitched = true;

                    //Debug.Log(camZoomSize);
                }
            }
            else if (minDistance > (dangerRange + 0.5f) || closestMonster == null)
            {
                if (camSwitched)
                {
                    mainCamCon.offsetX = camOffSetX;
                    mainCamCon.offsetZ = camOffSetZ;
                    mainCamCon.Zoom(camZoomSize);
                    //Debug.Log(camZoomSize);
                    camSwitched = false;
                }
            }
        }
    }