/// <summary>
    /// Attacks the target when in range.
    /// </summary>
    private IEnumerator Attack()
    {
        while (true)
        {
            if (agentState == AgentState.Attacking)
            {
                if (target == null)
                {
                    break;
                }

                shooting = true;

                agent.destination = transform.position;
                transform.LookAt(target.transform);

                gun.Shoot();

                if (Vector3.Distance(transform.position, target.position) > targetAttackDistance)
                {
                    agentState = AgentState.Tracking;
                }
            }
            else
            {
                shooting = false;
            }
            yield return(new WaitForSeconds(targetAttackInterval));
        }
    }
示例#2
0
    private void OnTriggerPress(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
    {
        if (behaviour != null)
        {
            if (behaviour.Shoot())
            {
                if (source != null)
                {
                    source.Stop();
                    source.clip = clipShoot;
                    source.Play();
                }

                if (gunAnimator != null)
                {
                    gunAnimator.SetTrigger("Shoot");
                }
            }
            else
            {
                if (source != null)
                {
                    source.Stop();
                    source.clip = clipEmpty;
                    source.Play();
                }
            }
        }
        else
        {
            Debug.LogWarning(this + " Component is missing GunBehaviour script!");
        }
    }
示例#3
0
 // Update is called once per frame
 void Update()
 {
     Move();
     gun.Shoot(ammo, projectilePos);
     SwitchWeapon();
     SwitchAmmo();
 }
示例#4
0
    public void Shoot(Vector2 Target)
    {
        if (DEBUG)
        {
            Debug.Log("I am trying to shoot at: " + Target);
        }

        //Shoot The Gun
        if (Gun)
        {
            Gun.Shoot();
        }
    }
示例#5
0
    void Update()
    {
        if (info.IsAutomatic)
        {
            if (Input.GetButton("Fire1"))
            {
                RaycastHit hit;
                bool       hitSuccess;
                (hitSuccess, hit) = controller.Shoot();

                if (hitSuccess)
                {
                    if (hit.transform.CompareTag("Target"))
                    {
                        TargetBehaviour target = hit.transform.GetComponent <TargetBehaviour>();
                        target.TakeDamage(Convert.ToSingle(info.Damage));
                    }
                }
            }
        }
    }