// Change the selected cop
    public void switchCurrentCop(PolicemanScript cop)
    {
        if (canSelectUnit)
        {
            int i;

            currentCop = cop.gameObject;

            // Unselect the cops
            for (i = 0; i < 5; ++i)
            {
                if (listOfCops[i] != currentCop)
                {
                    listOfCops[i].GetComponent <PolicemanScript>().deactivate();
                }
                else
                {
                    currentCopIndex = i;
                }
            }

            // selected the wanted one
            currentCop.GetComponent <PolicemanScript>().activate();
        }
    }
Esempio n. 2
0
    void OnTriggerExit(Collider collider)
    {
        if (collider.tag == "Enemy")
        {
            if (this.target == collider.gameObject.GetComponent <EnemyControllerScript>())
            {
                this.target = null;
            }
            this.enemyInVision.Remove(collider.gameObject.GetComponent <EnemyControllerScript>());

            GameObject[] gos  = GameObject.FindGameObjectsWithTag("Cop");
            bool         find = false;
            foreach (GameObject go in gos)
            {
                PolicemanScript ps = go.GetComponent <PolicemanScript>();
                if (ps.enemyInVision.Contains(collider.gameObject.GetComponent <EnemyControllerScript>()))
                {
                    find = true;
                    break;
                }
            }
            if (!find && collider.gameObject.GetComponent <EnemyControllerScript>().Pv > 0)
            {
                collider.gameObject.renderer.enabled = false;
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (GameManagerScript.gameState == GameManagerScript.GameState.START && this.Pv > 0 && this.executeActions)
        {
            if (this.target == null)
            {
                if (this.PolicemanVisible.Count > 0)
                {
                    this.target = this.PolicemanVisible[0];
                }
            }

            if (this.target)
            {
                if (this.target.Pv > 0)
                {
                    if (Time.time >= this.previousTime + this.attackSpeed)
                    {
                        //Instanciate the bullet
                        GameObject go = Instantiate(this.BulletPrefab, this.transform.position, Quaternion.identity) as GameObject;
                        go.transform.LookAt(this.target.transform);
                        this.previousTime = Time.time;
                    }
                }
                else
                {
                    this.PolicemanVisible.Remove(this.target);
                    this.target = null;
                }
            }
        }
    }
 void OnTriggerExit(Collider collider)
 {
     if (collider.tag == "Cop")
     {
         if (this.target == collider.gameObject.GetComponent <PolicemanScript>())
         {
             this.target = null;
         }
         this.PolicemanVisible.Remove(collider.GetComponent <PolicemanScript>());
     }
 }
 public bool isSeeingPoliceman(PolicemanScript policeman)
 {
     foreach (PolicemanScript police in this.PolicemanVisible)
     {
         if (police == policeman)
         {
             return(true);
         }
     }
     return(false);
 }