Ejemplo n.º 1
0
    private void FixedUpdate()
    {
        // increment the timer
        timer += Time.deltaTime;
        // calculate the distance between the subject and the target
        enemyDistance = Vector3.Distance(transform.position, player.transform.position);

        // if the enemy is far enough away, break engagement
        if (enemyDistance >= breakEnagementDistance)
        {
            // enable patrol, disable attack state
            patrol.enabled = true;
            this.enabled   = false;
        }

        // if the subject is close enough to the player to deal damage
        if (enemyDistance <= damageDistance && timer >= damageInterval)
        {
            Debug.Log("damage has been dealt");
            // reset the timer
            timer = 0;
            // damage the player
            assetManager.VariableDamage(damage);
        }

        // move the subject forward relative to itself.
        transform.Translate(Time.deltaTime * speed * Vector3.forward);

        // find the rotation to face the enemy
        var rotation = Quaternion.LookRotation(player.transform.position - transform.position);

        // rotate by interpolation to face the enemy
        transform.rotation = Quaternion.Slerp(transform.rotation, rotation, turnDamping * Time.deltaTime);
    }
Ejemplo n.º 2
0
 private void Update()
 {
     if (Vector3.Distance(transform.position, player.transform.position) <= 1500)
     {
         assetManager.VariableDamage(10 * Time.deltaTime);
     }
 }
Ejemplo n.º 3
0
    private void FixedUpdate()
    {
        // increment the timer by the amount of time that has passed
        timer += Time.deltaTime;

        // check the distance to the player
        distance = Vector3.Distance(player.transform.position, transform.position);

        // if the player is in attack range, and sufficient time has passed
        if (distance <= damageDistance && timer >= attackInterval)
        {
            timer = 0;
            assetManager.VariableDamage(10);
        }

        // move the subject directly forward
        transform.Translate(Time.deltaTime * speed * Vector3.forward, Space.Self);
        // and match the rotation of the child to the rotation of the parent.
        // we use the game object as a reference to avoid the issue that we can have when the
        // parent switches between modes
        transform.rotation = parent.transform.rotation;
    }