public void Shoot()
    {
        // animation
        if (!m_animator.isAnimationPlaying)
        {
            m_animator.PlayAnimation(m_weaponInfo.shotAnimation, ShootAnimationFinished);
        }

        // sound
        m_audioSource.Play();

        // physics
        Ray ray = m_weaponCamera.ViewportPointToRay(new Vector2(0.5f, 0.5f));

        if (m_weaponInfo.projectile != null)
        {
            var rotation = Quaternion.LookRotation(ray.direction);
            Instantiate(m_weaponInfo.projectile, m_shootingOrigin.transform.position, rotation);
        }
        else
        {
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 100.0f, m_shootingMask))
            {
                var target = hit.collider.GetComponent <QuakeBehaviour>();
                if (target != null)
                {
                    target.TakeDamage(20);
                }

                Instantiate(m_hit, hit.point, Quaternion.LookRotation(-ray.direction));
            }
        }
    }
 void PlayRandomAnimation(MDLAnimation[] animations, Action finishCallback = null)
 {
     if (animations != null && animations.Length > 0)
     {
         var index = Random.Range(0, animations.Length);
         m_animator.PlayAnimation(animations[index], finishCallback);
     }
 }
Example #3
0
    public void Shoot()
    {
        // animation
        m_animator.PlayAnimation("shot_animation");

        // sound
        m_audioSource.Play();

        // physics
        Ray        ray = m_weaponCamera.ViewportPointToRay(new Vector2(0.5f, 0.5f));
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 100.0f, m_shootingMask))
        {
            var target = hit.collider.GetComponent <QuakeBehaviour>();
            if (target != null)
            {
                target.TakeDamage(20);
            }

            Instantiate(m_hit, hit.point, Quaternion.LookRotation(-ray.direction));
        }
    }