Example #1
0
    void Shoot(GamerController mainGameController, CharacterObject currentPlayer, int currentPlayerIndex, int opponentIndex)
    {
        // This is the ray which will hit the target
        RaycastHit hit;

        // This is for the effect of shooting
        muzzleFlash.Play();
        AudioClip clip = gunshot.clip;

        gunshot.PlayOneShot(clip);

        // Updates the stamina of the player
        mainGameController.UpdateEnergy(0.5f);

        // This condition is true only when we have hit something with our ray
        if (Physics.Raycast(this.gameObject.transform.position, this.gameObject.transform.forward, out hit, Range))
        {
            if (hit.transform.tag == "Player")
            {
                // This causes damage
                mainGameController.TakeDamage(opponentIndex);
            }
        }
        else
        {
            //Debug.Log("We didn't hit anything but we fired !!!");
        }
    }