Ejemplo n.º 1
0
    public void Shoot()
    {
        AttackerState character_state = GetComponent <AttackerState>();
        GameObject    missile         = null;

        switch (character_state.gunPosition)
        {
        case AttackerState.GunPosition.MIDDLE:
            missile = (GameObject)Instantiate(missileRoot, transform.position + middlemuzzle, Quaternion.identity);
            break;

        case AttackerState.GunPosition.TOP:
            missile = (GameObject)Instantiate(missileRoot, transform.position + topmuzzle, Quaternion.identity);
            break;
        }
        missile.GetComponent <Missile>().speed = 7.0f / FindObjectOfType <BeatGenerator>().GetTimeDelta();
        switch (character_state.location)
        {
        case AttackerState.Location.LEFT:
            missile.GetComponent <Missile>().direction = Missile.Direction.RIGHT;
            break;

        case AttackerState.Location.RIGHT:
            missile.GetComponent <Missile>().direction = Missile.Direction.LEFT;
            break;
        }
    }
Ejemplo n.º 2
0
        public void Update()
        {
            if (Target == null)
            {
                return;
            }
            var dist = Vector3.Distance(Target.transform.position, this.transform.position);

            switch (state)
            {
            case AttackerState.Attacking:
                var dir = Target.transform.position - this.transform.position;

                if (dist >= attackRange)
                {
                    self.Move(dir.normalized);
                }

                else if (dist < attackRange)
                {
                    if (CO_Attack == null && Target.CurrentHealth > 0)
                    {
                        CO_Attack = StartCoroutine(DealDamageRoutine());
                    }
                    else if (Target.CurrentHealth <= 0)
                    {
                        Target = null;
                    }
                }

                else if (dist > detectionRange)
                {
                    StopCoroutine(CO_Attack);
                    state = AttackerState.Searching;
                }

                break;

            case AttackerState.Searching:
                if (dist <= detectionRange)
                {
                    state = AttackerState.Attacking;
                }

                break;
            }
        }