Ejemplo n.º 1
0
    /// <summary>
    /// openfire function
    /// </summary>
    public void OpenfireEvent()
    {
        RaycastHit hitInfo;

        bool ifHitSomething = Physics.SphereCast(transform.position, m_BoxCollider.bounds.size.x,
                                                 this.transform.forward, out hitInfo, this.attackRange);

        //if the ai tank in player attack range,we reduce the life value of ai tank
        if (ifHitSomething == true && hitInfo.transform.CompareTag("AITank"))
        {
            LifeSystem lifeSystem = hitInfo.transform.GetComponent <LifeSystem>();

            lifeSystem.ChangeCurrentLifeValue(-10.0f);
        }
    }
Ejemplo n.º 2
0
    public override void OnUpdate()
    {
        //AI originalRotation
        Quaternion originalRotation = this.m_AIController.transform.rotation;

        //AI targetRotation
        Quaternion targetRotation = Quaternion.LookRotation(m_AttackTarget.transform.position - this.m_AIController.transform.position);

        //turn to the attack target
        this.m_AIController.transform.rotation = Quaternion.Slerp(originalRotation, targetRotation, Time.deltaTime * m_TurrentRotateSpeed);

        RaycastHit hitInfo;

        //detect if the gun of AI has aimed the attack target
        bool ifHitSomething = Physics.SphereCast(this.m_AIController.transform.position, m_NavMeshAgent.radius,
                                                 this.m_AIController.transform.forward, out hitInfo, this.m_AIController.sightRange);

        //if AI has aimed the attack target
        if (ifHitSomething == true && hitInfo.transform.CompareTag("PlayerTank"))
        {
            if (Time.time > m_AttackIntervalTimer)
            {
                m_AttackIntervalTimer = Time.time + m_AttackInterval;

                //play the openfire animation
                m_Animator.SetTrigger("openfire");

                //if attack target has the life system,reduce it life value
                LifeSystem lifeSystem = hitInfo.transform.GetComponent <LifeSystem>();

                if (lifeSystem != null)
                {
                    lifeSystem.ChangeCurrentLifeValue(-10.0f);
                }
            }
        }
    }