Exemple #1
0
 // Use this for initialization
 void Start()
 {
     instance           = this;
     currentHealth      = maxHealth;
     shieldRend.enabled = false;
     InvokeRepeating("updateShieldText", 1.0f, 1.0f);
 }
Exemple #2
0
    /*
     *                  Comment sections for Shoot() function
     * This is where I will use a Raycast to see if I hit the player character
     * I will also need to randomize the enemys accuracy
     *      I will do that by: Getting the players x, y, & z position and then
     *      adding a random number to that number within a range that I can set
     *      in unity.
     *      So for example it should look something like
     *              playerPositionX + randomNumber1
     *              playerPositionY + randomNumber2
     *              playerPositionZ + randomNumber3
     *
     *              Raycast from enemyPosition to playerPositionRandom
     *   *** I do not know if the above note will work. I have not tested anything
     *       this is just my thought process on maybe how to get this done ***
     *
     *
     *      *** Tested & Works ***
     *  You can get the players position by typing: target.position
     *  You can get the Enemys position by typing: rb.position
     *
     *  Changed the enemys fire position to enemyShootPoint.transform.position
     *      I made a small sphere collider at the tip of the enemys pen to have
     *      as a reference for where to shoot from.
     */
    void Shoot()
    {
        // Debug.Log("Shoot() function has been called");

        muzzleFlash.Play();

        RaycastHit hit;

        if (Physics.Raycast(enemyShootPoint.transform.position, target.position, out hit, range))
        {
            Debug.Log("Enemy Hit: " + hit.transform.name);

            // Here I will call in a reference to the Target script to apply "damage" to the player
            playerDamage playerDamage = hit.transform.GetComponent <playerDamage>();
            if (playerDamage != null)
            {
                playerDamage.TakeDamage(damage);
            }
        }
    }