Example #1
0
    void ShootArrow()
    {
        timerBullets = 0f;
        effecttime   = 0f;

        gunAudio.Play();

        gunLight.color   = new Color(0.9f, 0.9f, 0.0f);
        gunLight.enabled = true;

        gunParticles.Stop();
        gunParticles.Play();

        gunLine.material = this.materials[0];

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);


        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            EnemyHealth enemyHealth = shootHit.collider.GetComponent <EnemyHealth>();
            if (enemyHealth != null)
            {
                enemyHealth.TakeDamage(damagePerShot, shootHit.point);

                MsgCSAttack msg = new MsgCSAttack(this.GetComponentInParent <EntityAttributes>().EntityID, shootHit.collider.GetComponent <EntityAttributes>().EntityID, shootRay.origin, shootHit.point, MsgCSAttack.WEAPON_ATTACK);

                NetworkMsgSendCenter msgcenter = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkMsgSendCenter>();
                msgcenter.SendMessage(msg);
            }
            else
            {
                MsgCSAttack msg = new MsgCSAttack(this.GetComponentInParent <EntityAttributes>().EntityID, -1, new Vector3(0, 0, 0), new Vector3(0, 0, 0), MsgCSAttack.WEAPON_ATTACK);

                NetworkMsgSendCenter msgcenter = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkMsgSendCenter>();
                msgcenter.SendMessage(msg);
            }

            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);

            MsgCSAttack msg = new MsgCSAttack(this.GetComponentInParent <EntityAttributes>().EntityID, -1, new Vector3(0, 0, 0), new Vector3(0, 0, 0), MsgCSAttack.WEAPON_ATTACK);

            NetworkMsgSendCenter msgcenter = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkMsgSendCenter>();
            msgcenter.SendMessage(msg);
        }
    }
Example #2
0
    void ShootMagic()
    {
        timerMagic = 0f;
        effecttime = 0f;

        gunAudio.Play();
        gunLight.enabled = true;
        gunLight.color   = new Color(0.1f, 0.3f, 1.0f);

        gunParticles.Stop();
        gunParticles.Play();

        gunLine.material = this.materials[1];

        gunLine.enabled = true;
        gunLine.SetPosition(0, transform.position);

        shootRay.origin    = transform.position;
        shootRay.direction = transform.forward;

        if (Physics.Raycast(shootRay, out shootHit, range, shootableMask))
        {
            float      radius    = 3.0f;
            Collider[] colliders = Physics.OverlapSphere(shootHit.point, radius);

            foreach (Collider cld in colliders)
            {
                EnemyHealth enemyHealth = cld.GetComponent <EnemyHealth>();
                if (enemyHealth != null)
                {
                    enemyHealth.TakeMagicDamage(this.magicPerShot);
                }
            }

            if (colliders.Length > 0)
            {
                MsgCSAttack msg = new MsgCSAttack(this.GetComponentInParent <EntityAttributes>().EntityID, shootHit.collider.GetComponent <EntityAttributes>().EntityID, shootRay.origin, shootHit.point, MsgCSAttack.MAGIC_ATTACK);

                NetworkMsgSendCenter msgcenter = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkMsgSendCenter>();
                msgcenter.SendMessage(msg);
            }
            else
            {
                MsgCSAttack msg = new MsgCSAttack(this.GetComponentInParent <EntityAttributes>().EntityID, -1, new Vector3(0, 0, 0), new Vector3(0, 0, 0), MsgCSAttack.MAGIC_ATTACK);

                NetworkMsgSendCenter msgcenter = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkMsgSendCenter>();
                msgcenter.SendMessage(msg);
            }

            gunLine.SetPosition(1, shootHit.point);
        }
        else
        {
            gunLine.SetPosition(1, shootRay.origin + shootRay.direction * range);

            MsgCSAttack msg = new MsgCSAttack(this.GetComponentInParent <EntityAttributes>().EntityID, -1, new Vector3(0, 0, 0), new Vector3(0, 0, 0), MsgCSAttack.MAGIC_ATTACK);

            NetworkMsgSendCenter msgcenter = GameObject.FindGameObjectWithTag("NetworkManager").GetComponent <NetworkMsgSendCenter>();
            msgcenter.SendMessage(msg);
        }
    }