void Start()
    {
        GameObject[] templightarray = new GameObject[1];
        templightarray = GameObject.FindGameObjectsWithTag("Flashlight"); // grabs a copy of every flashlight in the scene
        Light2D templightobject;

        flashlightObject  = new GameObject[3];
        flashlightLight2D = new Light2D[3];
        int j = 0;

        for (int i = 0; i < templightarray.Length; ++i)
        {
            if (Vector2.Distance(transform.position, templightarray[i].transform.position) < 1f)
            {
                templightobject = templightarray[i].GetComponent <Light2D>();
                if (templightobject.pointLightOuterRadius == 7.5f) // change the float to be the outter radius of the lowest alert level flashlight
                {
                    flashlightObject[0]  = templightarray[i];
                    flashlightLight2D[0] = templightobject;
                }
                else if (templightobject.pointLightOuterRadius == 8.5f) // change the float to be the outter radius of the medium alert level flashlight
                {
                    flashlightObject[1]  = templightarray[i];
                    flashlightLight2D[1] = templightobject;
                }
                else if (templightobject.pointLightOuterRadius == 10f) // change the float to be the outter radius of the highest alert level flashlight
                {
                    flashlightObject[2]  = templightarray[i];
                    flashlightLight2D[2] = templightobject;
                }
            }
        }
        flashlightObject[1].SetActive(false); // disables the two higher alert flashlights
        flashlightObject[2].SetActive(false);
        waitTime         = startWaitTime;
        pathfindingIndex = 0;
        isPathfinding    = false;
        isSearching      = false;
        actualPlayer     = GameObject.FindGameObjectWithTag("Player");
        closestWaypoint  = gameObject.GetComponent <ClosestWaypoint>();
        wscopy           = closestWaypoint.GetComponent <WaypointScript>();
        patrolRoute      = new Transform[routeWaypoints.Length];

        index = 0;
        foreach (GameObject node in routeWaypoints)
        {
            patrolRoute[index] = node.transform;
            index++;
        }
        waitTime = startWaitTime;
    }
Exemplo n.º 2
0
 private void Start()
 {
     gmcopy   = GetComponentInParent <GuardMechanics>();
     player   = GameObject.FindGameObjectWithTag("Player");
     playercw = player.gameObject.GetComponent <ClosestWaypoint>();
 }
Exemplo n.º 3
0
 // Update is called once per frame
 void FixedUpdate()
 {
     if (!trackingPlayer)
     {
         if (hinge.jointAngle >= maxLim) // if we've rotated our maximum amount, rotate the other way
         {
             if (waitTime <= 0)
             {
                 motorCopy.motorSpeed = 0 - rotationSpeed;
                 hinge.motor          = motorCopy;
                 hinge.useMotor       = true;
             }
             else
             {
                 hinge.useMotor = false;
                 waitTime      -= Time.fixedDeltaTime;
             }
         }
         else if (hinge.jointAngle <= minLim)
         {
             if (waitTime <= 0)
             {
                 motorCopy.motorSpeed = rotationSpeed;
                 hinge.motor          = motorCopy;
                 hinge.useMotor       = true;
             }
             else
             {
                 hinge.useMotor = false;
                 waitTime      -= Time.fixedDeltaTime;
             }
         }
         else if (waitTime <= 0)
         {
             waitTime = rotationWaitTime;
         }
     }
     else
     {
         Vector2 direction = new Vector2(transform.position.x - player.transform.position.x, transform.position.y - player.transform.position.y);
         if (hinge.jointAngle < maxLim && hinge.jointAngle > minLim)
         {
             transform.up = direction;
             if (guardSummoned == false)
             {
                 ClosestWaypoint cwcopy = player.GetComponent <ClosestWaypoint>();
                 assignedGuard.SendMessage("StartMoveToWaypoint", cwcopy.closestWaypoint);
                 guardSummoned = true;
             }
         }
     }
     if (guardSummoned == true)
     {
         if (guardwait <= 0)
         {
             guardSummoned = false;
             guardwait     = guardCooldown;
         }
         else
         {
             guardwait -= Time.fixedDeltaTime;
         }
     }
 }