Пример #1
0
    // Use this for initialization
    void Start()
    {
        //Get the EnemyAIValue.cs script of this enemy
        valueScript = GetComponent <EnemyAIValue>();
        if (valueScript == null)
        {
            Debug.LogError(this + " doesn't have a EnemyAIValue.cs script!");
        }

        //Get the walls of the map
        if (valueScript.hasWallManager)
        {
            _mapWalls = valueScript.wallManager.getMapVectors();
        }
        else
        {
            _mapWalls = new WallVector[0];
        }

        //Starter les timer
        pathfindingUpdateTimer = valueScript.pathfindingUpdateRate;

        //Initialiser des variables
        exitState = new UnityEvent();
        exitState.AddListener(exitSearchState);
    }
Пример #2
0
    // Use this for initialization
    void Start()
    {
        //Get the EnemyAIValue.cs script of this enemy
        valueScript = GetComponent <EnemyAIValue>();
        if (valueScript == null)
        {
            Debug.LogError(this + " doesn't have a EnemyAIValue.cs script!");
        }

        //Get the detection scripts
        detectionScripts = new List <Detection>();
        if (valueScript.hasWallDetectionScript)
        {
            detectionScripts.Add(valueScript.wallDetection);
        }
        if (valueScript.hasProjectileDetectionScript)
        {
            detectionScripts.Add(valueScript.projDetection);
        }
        if (valueScript.hasTankDetectionScript)
        {
            detectionScripts.Add(valueScript.tankDetection);
        }

        //Initialiser directions et valeurs
        _directions = new Vector3[valueScript.nbDirection];
        createDirectionVector();
        initialiseDirectionsValueMatrices();

        //Initialiser la direction actuelle
        _currentDirection = Vector3.zero;

        //Initialiser les timer
        updateTimer = valueScript.mouvementUpdateRate;
    }
Пример #3
0
    // Use this for initialization
    void Start()
    {
        //Find the EnemyAIValue.cs script
        valueScript = GetComponent <EnemyAIValue>();
        if (valueScript == null)
        {
            Debug.LogError(this + " doesn't have a EnemyAIValue.cs script!");
        }

        //Make sure the script has a cannon
        if (cannon == null)
        {
            Debug.LogError(this + " is missing a reference to a cannon object!");
        }

        //Calculer la distance à la laquelle créer le projectile
        if (cannon != null)
        {
            if (cannon.GetComponentInChildren <Transform>() != null)
            {
                spawnDistance = cannon.GetComponentInChildren <Transform>().localScale.z + cannon.transform.localScale.z + projectile.transform.localScale.z;
            }
        }
        else
        {
            spawnDistance = 0;
        }

        //Initialiser le timer
        fireTimer = fireRate / 2;
    }
Пример #4
0
    // Use this for initialization
    void Start()
    {
        //Get the EnemyAIValue.cs script of this enemy
        valueScript = GetComponent <EnemyAIValue>();
        if (valueScript == null)
        {
            Debug.LogError(this + " doesn't have a EnemyAIValue.cs script");
        }

        obstacles = new List <WallVector>();
    }
Пример #5
0
    // Use this for initialization
    void Start()
    {
        //Find the EnemyAIValue.sc script
        valueScript = GetComponent <EnemyAIValue>();
        if (valueScript == null)
        {
            Debug.Log(this + " doesn't have a EnemyAIValue.cs script!");
        }

        isExploding    = false;
        explosionTimer = 0;
    }
Пример #6
0
    // Use this for initialization
    void Start()
    {
        //Find the EnemyAIValue.cs script
        valueScript = GetComponent <EnemyAIValue>();
        if (valueScript == null)
        {
            Debug.LogError(this + " doesn't have a EnemyAIValue.cs script!");
        }

        //Désactiver l'effet de burst
        if (burstEffect != null)
        {
            burstEffect.SetActive(false);
        }
        isInBurst = false;
    }
Пример #7
0
    public override void play()
    {
        //Permettre au tank de bouger
        EnemyAIValue valueScript = GetComponent <EnemyAIValue>();

        if (valueScript != null)
        {
            if (valueScript.hasMouvementScript)
            {
                valueScript.enemyMouvement.canMove = true;
            }
        }

        //Activer les scripts de comportement
        EnemyBehavior[] behaviorScripts = GetComponents <EnemyBehavior>();
        foreach (EnemyBehavior behaviorScript in behaviorScripts)
        {
            behaviorScript.enable();
        }
    }
Пример #8
0
    public override void pause()
    {
        //Empêcher le tank de bouget
        EnemyAIValue valueScript = GetComponent <EnemyAIValue>();

        if (valueScript != null)
        {
            if (valueScript.hasMouvementScript)
            {
                valueScript.enemyMouvement.canMove = false;
            }
        }

        //Désactiver les scripts de comportement
        EnemyBehavior[] behaviorScripts = GetComponents <EnemyBehavior>();
        foreach (EnemyBehavior behaviorScript in behaviorScripts)
        {
            behaviorScript.disable();
        }
    }
Пример #9
0
    /* Les méthodes dans cette section calcule une valeur pour chaque direction en fonction
     *  de divers paramètres. Toutes les méthodes sont appelées par calculateDirectionsValues()
     */

    /// <summary>
    ///     Calcule la valeur de chaque direction en fonction de possible collisions avec d'autre tank. La méthode ne prend en compte
    ///         que les tanks immobiles et ceux dont le déplacement est parallèle au tank.
    /// <summary>
    private void checkForCollision()
    {
        Collider[] colliders;

        //Vérifier chaque direction
        for (int i = 0; i < valueScript.nbDirection; i++)
        {
            //Vérifier s'il y a des tanks dans la direction
            colliders = GeneralFunction.projectRectangle(transform.position, valueScript.enemyMouvement.directions[i], valueScript.rayonCollision * 2, valueScript.rayonDetectionTank);
            foreach (Collider collider in colliders)
            {
                if (collider.GetComponent <EnemyMain>() != null && collider.gameObject != this.gameObject)
                {
                    EnemyAIValue tankValueScript = collider.GetComponent <EnemyAIValue>();
                    if (tankValueScript != null && tankValueScript.hasMouvementScript)
                    {
                        //Vérifier si le tank est immobile ou s'il se déplace parallèlement à la direction
                        if (tankValueScript.state == EnemyAIValue.State.Idle || tankValueScript.enemyMouvement.currentDirection == Vector3.zero)
                        {
                            directionsValues[i] -= IMMOBILE_TANK_FLAT_MALUS;
                        }
                        //Vérifier si le tank se déplace parallèlement à la direction
                        else
                        {
                            //Calculer l'angle entre la direction du tank et la direction
                            Vector3 selfDirection  = valueScript.enemyMouvement.directions[i];
                            Vector3 otherDirection = tankValueScript.enemyMouvement.currentDirection;
                            float   angle          = Vector3.Angle(selfDirection, otherDirection);

                            if (angle <= 10 || angle >= 170)
                            {
                                directionsValues[i] -= IMMOBILE_TANK_FLAT_MALUS;
                            }
                        }
                    }
                }
            }
        }
    }
Пример #10
0
    // Use this for initialization
    void Start()
    {
        //Find the CreateProjectile.cs script
        shoot = GetComponent <CreateProjectile>();
        if (shoot == null)
        {
            Debug.LogError(this + " requires a CreateProjectile.cs script to function!");
        }

        //Find the EnemyAIValue.cs script
        valueScript = GetComponent <EnemyAIValue>();
        if (valueScript == null)
        {
            Debug.LogError(this + " doesn't have a EnemyAIValue.cs script!");
        }

        //Trouver la tourelle du tank
        Transform[] transforms = GetComponentsInChildren <Transform>();
        foreach (Transform transform in transforms)
        {
            if (transform.gameObject.name == "body" || transform.gameObject.name == "Body")
            {
                turret = transform.gameObject;
            }
        }
        if (turret == null)
        {
            Debug.Log("Le tank ne possède pas de tourelle!");
        }

        //Vérifier que le script possède un prefab de projectile
        if (projectile == null)
        {
            Debug.LogError(this + " requires a GameObject projectile to shoot!");
        }

        //Initialiser le timer
        fireTimer = 0;
    }