Patrol.StartPatrol C# (CSharp) Method

StartPatrol() public method

public StartPatrol ( ) : void
return void
    public void StartPatrol()
    {
        for(int x = 0; x < patrolMarkers.Length; x++){
          GameObject.Destroy(patrolMarkers[x]);
        }
        if(setNewPatrol){
          float closestPoint = Mathf.Infinity;
          int startPoint = 0;

          for(int y = 0; y < patrolTarget.Length; y++){
        float fDistance = (myTransform.position - patrolTarget[y]).sqrMagnitude;

        if(fDistance < closestPoint){
          closestPoint = fDistance;
          startPoint = y;
        }

          }
          cdroneScript.AIScript.ClickedTargetPosition(patrolTarget[startPoint]);
          patrolIndex = startPoint;
          setNewPatrol = false;
        }
        /*
        if(Vector3.Distance(this.transform.position,patrolTarget[patrolIndex]) < 5.0f){
          //if(!AstarAIFollow.onAIMovingChange) {
          patrolIndex += 1;
          if(patrolIndex >= patrolTarget.Length) patrolIndex = 0;
        cdroneScript.AIScript.ClickedTargetPosition(patrolTarget[patrolIndex]);
        }*/
        //}
    }

Usage Example

Example #1
0
    void SpawnPolice()
    {
        int        spawnPointIndex = Random.Range(0, SpawnPointsPolice.Count);
        GameObject police          = Instantiate(Police, SpawnPointsPolice[spawnPointIndex].position,
                                                 SpawnPointsPolice[spawnPointIndex].rotation);

        // set variables of police
        Patrol policePatrol = police.GetComponent <Patrol>();

        policePatrol.moveSpots    = GameManager.instance.MoveSpots;
        policePatrol.playerTarget = player.transform;
        policePatrol.StartPatrol();
    }
All Usage Examples Of Patrol::StartPatrol