Exemplo n.º 1
0
    private void OnCollisionEnter(Collision collision)
    {
        //If the shell isn't live, leave.
        if (!isLive)
        {
            return;
        }

        //The shell is going to explode and is no longer live
        isLive = false;

        //Show visual explosion
        GameObject explosion = Instantiate(explosionEffect, collision.contacts[0].point, Quaternion.identity) as GameObject;

        Destroy(explosion, 3f);

        //If this is not the server, leave. The above code doesn't need to be
        //run only on the server since it only deals with the graphical explosion. Since
        //the code below handles actually harming other tanks, it should only be run on
        //the server

        if (!isServer)
        {
            return;
        }

        AttackerCharacter attacker = collision.collider.GetComponent <AttackerCharacter>();

        if (attacker != null)
        {
            attacker.TakeDamage(damage);
        }

        NetworkServer.Destroy(gameObject);
    }
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        AttackerCharacter attackerCharacter = animator.GetComponent <AttackerCharacter>();

        if (attackerCharacter != null)
        {
            attackerCharacter.Attack();
        }
    }