Esempio n. 1
0
    protected override void Update()
    {
        plantText.text  = ((int)timeToPlant).ToString();
        defuseText.text = ((int)timeToDefuse).ToString();
        //timer -= Time.deltaTime;
        if (!isActiveAndEnabled || target == null)
        {
            return;
        }

        targetDistance = Vector3.Distance(target.transform.position, transform.position);

        if (!isPlanting && !isDefusing)
        {
            LookAtTarget();
        }

        var distancePlant  = Vector2.Distance(enemyBase.transform.position, transform.position);
        var distanceDefuse = Vector2.Distance(allyBase.transform.position, transform.position);


        if (isInChargeOfPlantingBomb)
        {
            fighting = false;
            if (team == Team.Ally && player_bomb.PlantingBomb == true)
            {
                isInChargeOfPlantingBomb = false;
                return;
            }//Seteo la base enemiga como target
            if (!enemyBase.Planted && enemyBase.actualHealth > 0)
            {
                GoToPlantBomb();
            }
            //Si estoy cerca de la base enemiga, planto
            if (distancePlant <= minBombDistance && !enemyBase.Planted)
            {
                PlantBomb();
            }
            if (isPlanting == true)
            {
                wait = true;
                plantText.gameObject.SetActive(true);
                timeToPlant -= Time.deltaTime;
                if (timeToPlant <= 0)
                {
                    AIBombManager.Instance.AssingBombDefuser(team);
                    enemyBase.PlantBomb(team);
                    plantText.gameObject.SetActive(false);
                    wait = false;
                    isInChargeOfPlantingBomb = false;
                    isPlanting  = false;
                    timeToPlant = 3f;
                    target      = FindBombPlanter();
                }
            }
        }
        else if (isInChargeOfDefusingBomb)
        {
            fighting = false;
            if (team == Team.Ally && player_bomb.DefusingBomb == true)
            {
                isInChargeOfDefusingBomb = false;
                return;
            }
            if (allyBase.Planted)
            {
                GoDefuseBomb();
            }
            if (distanceDefuse <= minBombDistance && allyBase.Planted)
            {
                DefuseBomb();
            }
            if (isDefusing == true)
            {
                wait = true;
                defuseText.gameObject.SetActive(true);
                timeToDefuse -= Time.deltaTime;
                if (timeToDefuse <= 0)
                {
                    allyBase.DefuseBomb(team);
                    defuseText.gameObject.SetActive(false);
                    wait = false;
                    isInChargeOfDefusingBomb = false;
                    isDefusing   = false;
                    timeToDefuse = 3f;
                    target       = FindDefuser();
                }
            }
        }
        else
        {
            fighting = true;
            if (targetDistance < chaseDistance)
            {
                if (targetDistance > attackDistance)
                {
                    ChaseTarget();
                }
                else
                {
                    Attack();
                }
            }
        }
        base.Update();
    }
Esempio n. 2
0
    protected override void Update()
    {
        base.Update();

        var distancePlant  = Vector2.Distance(enemyBase.transform.position, transform.position);
        var distanceDefuse = Vector2.Distance(allyBase.transform.position, transform.position);

        plantText.text  = ((int)plantTimer).ToString();
        defuseText.text = ((int)defuseTimer).ToString();

        if (!enemyBase.Planted)
        {
            if (distancePlant <= minBombDistance)
            {
                if (Input.GetKey(KeyCode.E))
                {
                    isPlantingBomb = true;
                    plantText.gameObject.SetActive(true);
                    plantTimer -= Time.deltaTime;
                    if (plantTimer <= 0)
                    {
                        enemyBase.PlantBomb(Team.Ally);
                        plantText.gameObject.SetActive(false);
                        plantTimer     = 3f;
                        isPlantingBomb = false;
                    }
                }
                else if (Input.GetKeyUp(KeyCode.E))
                {
                    plantText.gameObject.SetActive(false);
                    plantTimer     = 3f;
                    isPlantingBomb = false;
                }
            }
            else
            {
                plantText.gameObject.SetActive(false);
                isPlantingBomb = false;
            }
        }

        if (allyBase.Planted)
        {
            if (distanceDefuse <= minDefuseDistance)
            {
                if (Input.GetKey(KeyCode.E))
                {
                    defusingBomb = true;
                    defuseText.gameObject.SetActive(true);
                    defuseTimer -= Time.deltaTime;
                    if (defuseTimer <= 0)
                    {
                        allyBase.DefuseBomb(Team.Ally);
                        defuseText.gameObject.SetActive(false);
                        defuseTimer  = 3f;
                        defusingBomb = false;
                    }
                }
                else if (Input.GetKeyUp(KeyCode.E))
                {
                    defuseText.gameObject.SetActive(false);
                    defuseTimer  = 3f;
                    defusingBomb = false;
                }
            }
            else
            {
                defuseText.gameObject.SetActive(false);
                defusingBomb = false;
            }
        }
    }