Exemplo n.º 1
0
    } // end FIXED UPDATE

    // Element Damage Manager //
    public void ElementDamageManager(string element, EnemyHealthAndDeathManager enemyH, float modifier = 1f)
    {
        if (element == "fire" && enemyH != null)
        {
            enemyH.DamageEnemy((int)(fireDMG * modifier));
        }
        if (element == "ice" && enemyH != null)
        {
            enemyH.DamageEnemy(iceDMG);
            FreezeAIEnemy(enemyH.ai); // Freezing AI
        }
        if (element == "lighting" && enemyH != null)
        {
            enemyH.DamageEnemy(lightingDMG);
        }

        if (element == "fireice" && enemyH != null)
        {
            enemyH.DamageEnemy((int)(fireiceDMG * modifier));
        }

        if (element == "icelight" && enemyH != null)
        {
            enemyH.DamageEnemy(icelightDMG);
        }

        if (element == "lightfire" && enemyH != null)
        {
            enemyH.DamageEnemy(lightfireDMG);
        }
    }
Exemplo n.º 2
0
    // Collision counter //
    void OnCollisionEnter(Collision col)
    {
        EnemyHealthAndDeathManager enemyHealth = col.gameObject.GetComponentInParent <EnemyHealthAndDeathManager>();

        if (enemyHealth != null)
        {
            //print("sphere");
            magicSystem.ElementDamageManager("fire", enemyHealth);
            Instantiate(fireExplosion, transform.position, transform.rotation);
            Destroy(gameObject);
        }
    }
Exemplo n.º 3
0
    // Collision counter //
    void OnCollisionEnter(Collision col)
    {
        colCounter--;
        if (colCounter == 0)
        {
            Explode();
            return;
        }
        EnemyHealthAndDeathManager enemyHealth = col.gameObject.GetComponentInParent <EnemyHealthAndDeathManager>();

        if (enemyHealth != null)
        {
            Explode();
        }
    }
Exemplo n.º 4
0
 private void Explode()
 {
     Instantiate(fireExplosion, transform.position, transform.rotation);
     Collider[] hitObjs = Physics.OverlapSphere(transform.position, radius, enemyMask);
     for (int i = 0; i < hitObjs.Length; i++)
     {
         float distanceFromRadius = Vector3.Distance(transform.position, hitObjs[i].transform.position);
         float modNum             = Mathf.Max((radius - distanceFromRadius), 0f) / radius;
         EnemyHealthAndDeathManager enemyManager = hitObjs[i].GetComponentInParent <EnemyHealthAndDeathManager>();
         if (enemyManager != null)
         {
             magicSystem.ElementDamageManager(power, enemyManager, modNum);
         }
     }
     Destroy(gameObject);
 }
Exemplo n.º 5
0
    // Lightning Line Renderer
    private void LinerRendererShoot(Transform wand, string element, int RamDepleteAmt, LineRenderer Line)
    {
        Line.enabled = true;
        Vector3 camShootingPoint = cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); // Aiming point of the ray -> will be set to the middle position of the fps camera. Takes position of the camera and converts it to world space.

        RaycastHit hitObject;                                                            // Object that is hit with our ray; object must have a collider on

        Line.SetPosition(0, wand.position);                                              // starting position of the laserline is set to current position of the tip of the wand where the ray will shoot from
        GameObject particle;

        if (Physics.Raycast(camShootingPoint, cam.transform.forward, out hitObject, shootRange)) // Raycast is used to determine where the end of the ray will be, and deals force/damage to the object hit. Physics Raycast returns a bool. [camShootingPoin:] point in the world space where ray will begin [fpsCam:] Direction of the ray [Out - keyword:] Allows us to store information from a function + it's return type of the object hit. ex: Information like Rigidbody, collider, & surfacenormal of object hit. [shootRange:] How far ray goes.
        {
            Line.SetPosition(1, hitObject.point);                                                // if raycast returns true and an object is hit, we're setting the 2nd position of the laser line to that object point
            particle = Instantiate(yellowParticle, hitObject.point, Quaternion.identity);
            Destroy(particle, 0.1f);

            enemyHealth = hitObject.collider.GetComponentInParent <EnemyHealthAndDeathManager>();  // getting script from the object hit
            LightningReaction reaction = hitObject.collider.GetComponentInParent <LightningReaction>();
            enemyMonster = hitObject.collider.GetComponent <BaseAI>();

            if (reaction != null)
            {
                reaction.React();
            }

            if (enemyHealth != null || enemyMonster != null) // checking to make sure the hit object is an enemy type with script "EnemyHealthAndDamageManager" attached
            {
                ElementDamageManager(element, enemyHealth);  // if "EnemyHealthAndDamageManager" exists, then pass in the element
                particle = Instantiate(yellowParticle, hitObject.point, Quaternion.identity);
                Destroy(particle, 0.1f);
            }
            else
            {
                // nothing happens
            }
        }
        else // Raycast returns false
        {
            // nothing was hit
            Line.SetPosition(1, (camShootingPoint + (cam.transform.forward * shootRange))); // if nothing is hit, then the ray will just shoot 50 units away from the camera

            // Bullet Cloning //
            particle = Instantiate(yellowParticle, (camShootingPoint + (cam.transform.forward * shootRange)), Quaternion.identity);
            Destroy(particle, 0.1f);
        }
    }
Exemplo n.º 6
0
 // Element Magic Shooting //
 public void ShootElement(Transform wandPosition, GameObject Element, string power, int ramAmt, GameObject particleToInstantiate)
 {
     if (ramAmount >= ramAmt)
     {
         Transform  wand           = wandPosition;
         Quaternion BulletRotation = Quaternion.LookRotation(cam.transform.forward);
         Ray        ray            = cam.ScreenPointToRay(Input.mousePosition);
         Vector3    pointTo        = cam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));
         RaycastHit hitObj;
         GameObject elementToShoot = Instantiate(Element, wand.transform.position, Quaternion.identity);
         GameObject particle       = particleToInstantiate;
         if (Physics.Raycast(ray, out hitObj, shootRange))
         {
             Vector3 desitnation = elementToShoot.transform.position - hitObj.point;
             //Quaternion rotationDestination = Quaternion.LookRotation(-desitnation);
             elementToShoot.transform.localRotation = Quaternion.Lerp(elementToShoot.transform.rotation, cam.transform.rotation, 1);
             RamDepletion(ramAmt);
             enemyHealth  = hitObj.collider.GetComponentInParent <EnemyHealthAndDeathManager>(); // getting script from the object hit
             enemyMonster = hitObj.collider.GetComponent <BaseAI>();
             if (enemyHealth != null)                                                            // checking to make sure the hit object is an enemy type with script "EnemyHealthAndDamageManager" attached
             {
                 ElementDamageManager(power, enemyHealth);                                       // if "EnemyHealthAndDamageManager" exists, then pass in the element
                 RamDepletion(ramAmt);
                 Destroy(elementToShoot, 0.3f);                                                  //0.3
                 Instantiate(particle, hitObj.point, Quaternion.identity);
             }
             else
             {
                 RamDepletion(ramAmt);
                 Destroy(elementToShoot, 0.3f); //0.3
                 Instantiate(particle, hitObj.point, Quaternion.identity);
             }
         }
         else
         {
             //print("Did not hit");
             var position = ray.GetPoint(shootRange);
             //Vector3 position = ray.GetPoint(shootRange);
             Vector3 destintion = elementToShoot.transform.position - position;
             //Quaternion rotationDestination = Quaternion.LookRotation(-destintion);
             elementToShoot.transform.localRotation = Quaternion.Lerp(elementToShoot.transform.rotation, cam.transform.rotation, 1);
             RamDepletion(ramAmt);
             StartCoroutine(InstantiateParticle(particleToInstantiate, elementToShoot));
         }
     }
 }
Exemplo n.º 7
0
    private void Update()
    {
        //Ray ray = cam.ScreenPointToRay(Input.mousePosition);
        Ray        ray = new Ray(transform.position, transform.forward);
        RaycastHit hitObj;

        if (Physics.Raycast(ray, out hitObj, shootRange))
        {
            Vector3    desitnation                 = transform.position - hitObj.point;
            Quaternion rotationDestination         = Quaternion.LookRotation(-desitnation);
            EnemyHealthAndDeathManager enemyHealth = hitObj.collider.GetComponentInParent <EnemyHealthAndDeathManager>(); // getting script from the object hit

            if (enemyHealth != null)                                                                                      // checking to make sure the hit object is an enemy type with script "EnemyHealthAndDamageManager" attached
            {
                magicSystem.ElementDamageManager(element, enemyHealth);                                                   // if "EnemyHealthAndDamageManager" exists, then pass in the element
            }
        }
    }
Exemplo n.º 8
0
    // Creating elemental damages //

    void ElementDamageManager(string element, EnemyHealthAndDeathManager enemyH)
    {
        if (element == "fire" && enemyH != null)
        {
            if (LastHitElement == "ice")
            {
                fireDMG = 10;
                enemyH.DamageEnemy(fireDMG);
                print("success fire + ice");
            }
            else
            {
                // does regular damage
                fireDMG = 5;
                enemyH.DamageEnemy(fireDMG);
                //print("success fire");
            }
        }
        if (element == "ice" && enemyH != null)
        {
            iceDMG = 1;
            enemyH.DamageEnemy(iceDMG);  // Does very little damage
            FreezeAIEnemy();
        }
        if (element == "lighting" && enemyH != null)
        {
            if (LastHitElement == "lighting" != (LightingCounter == 5))
            {
                LightingCounter += 1;
                lightingDMG      = 3 * LightingCounter;
                enemyH.DamageEnemy(lightingDMG);
            }
            else
            {
                LightingCounter = 1;
                // does damage + increase damage if you conseutively hit an enemy AI
                lightingDMG = 3;
                enemyH.DamageEnemy(lightingDMG);
            }
        }
    }
Exemplo n.º 9
0
    } // end Start

    // Update is called once per frame
    void Update()
    {
        // LEFT BUTTON //
        if (Input.GetButtonDown("Fire1") && !Input.GetButtonDown("Fire2") && Time.time > nextFire && ramAmount != 0 && ramAmount > 0)
        {
            string element = Lelement; // storing the element information
            LastHitElement = Lelement;

            nextFire = Time.time + fireRate;                                                            // making sure player does not constantly fire
            StartCoroutine(ShotEffect(LlaserLine));                                                     // Calling the coroutine ShotEffect function to enable laser line

            Vector3 camShootingPoint = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0));         // Aiming point of the ray -> will be set to the middle position of the fps camera. Takes position of the camera and converts it to world space.

            RaycastHit hitObject;                                                                       // Object that is hit with our ray; object must have a collider on
            LlaserLine.SetPosition(0, LwandEnd.position);                                               // starting position of the laserline is set to current position of the tip of the wand where the ray will shoot from

            if (Physics.Raycast(camShootingPoint, fpsCam.transform.forward, out hitObject, shootRange)) // Raycast is used to determine where the end of the ray will be, and deals force/damage to the object hit. Physics Raycast returns a bool. [camShootingPoin:] point in the world space where ray will begin [fpsCam:] Direction of the ray [Out - keyword:] Allows us to store information from a function + it's return type of the object hit. ex: Information like Rigidbody, collider, & surfacenormal of object hit. [shootRange:] How far ray goes.
            {
                LlaserLine.SetPosition(1, hitObject.point);                                             // if raycast returns true and an object is hit, we're setting the 2nd position of the laser line to that object point
                RamDepletion();
                // Bullet Cloning //
                bulletClone = Instantiate(bullet, hitObject.point, Quaternion.identity);
                Destroy(bulletClone, 0.2f);

                enemyHealth  = hitObject.collider.GetComponent <EnemyHealthAndDeathManager>(); // getting script from the object hit
                enemyMonster = hitObject.collider.GetComponent <BaseAI>();

                if (enemyHealth != null)                        // checking to make sure the hit object is an enemy type with script "EnemyHealthAndDamageManager" attached
                {
                    ElementDamageManager(element, enemyHealth); // if "EnemyHealthAndDamageManager" exists, then pass in the element
                    RamDepletion();
                }
            }
            else // Raycast returns false
            {
                LlaserLine.SetPosition(1, (camShootingPoint + (fpsCam.transform.forward * shootRange))); // if nothing is hit, then the ray will just shoot 50 units away from the camera

                // Bullet Cloning //
                bulletClone = Instantiate(bullet, (camShootingPoint + (fpsCam.transform.forward * shootRange)), Quaternion.identity);
                Destroy(bulletClone, 0.2f);
                RamDepletion();
                //print((camShootingPoint + (fpsCam.transform.forward * shootRange)));
            }
        }

        // RIGHT BUTTON //
        if (Input.GetButtonDown("Fire2") && !Input.GetButtonDown("Fire1") && Time.time > nextFire && ramAmount != 0 && ramAmount > 0)
        {
            string element = Relement; // storing the element information
            LastHitElement = Relement;

            nextFire = Time.time + fireRate;                                                    // Prevent player from spamming fire button
            StartCoroutine(ShotEffect(RlaserLine));                                             // enabling the liner renderer

            Vector3 camShootingPoint = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); // Getting the mid point of the camera

            RaycastHit hitObject;                                                               // Raycast var storing information of the object hit
            RlaserLine.SetPosition(0, RwandEnd.position);                                       // setting starting position of the laser
            RamDepletion();

            if (Physics.Raycast(camShootingPoint, fpsCam.transform.forward, out hitObject, shootRange))
            {
                RlaserLine.SetPosition(1, hitObject.point); // setting end position of laser to the object hit

                // Bullet Cloning //
                bulletClone = Instantiate(bullet, hitObject.point, Quaternion.identity);
                Destroy(bulletClone, 0.2f);
                //print(hitObject.point);

                enemyHealth  = hitObject.collider.GetComponent <EnemyHealthAndDeathManager>(); // creating object of enemyhealthmanager
                enemyMonster = hitObject.collider.GetComponent <BaseAI>();

                if (enemyHealth != null)
                {
                    ElementDamageManager(element, enemyHealth); // if "EnemyHealthAndDamageManager" exists, then pass in the element
                    RamDepletion();
                }
            }
            else
            {
                // if it does not exist then cast the ray in a forward direction from the camera middle point
                RlaserLine.SetPosition(1, (camShootingPoint + (fpsCam.transform.forward * shootRange)));
                RamDepletion();
                bulletClone = Instantiate(bullet, (camShootingPoint + (fpsCam.transform.forward * shootRange)), Quaternion.identity);
                Destroy(bulletClone, 0.2f);
            }
        }

        // BOTH BUTTONS //
        if ((Input.GetButtonDown("Fire1") && Input.GetButtonDown("Fire2") || Input.GetButtonDown("Fire2") && Input.GetButtonDown("Fire1")) && Time.time > nextFire && ramAmount != 0 && ramAmount > 0)
        {
            // storing base material to reset later
            Material lMaterialBase = LlaserLine.material;
            Material rMaterialBase = RlaserLine.material;


            LastHitElement = "";
            nextFire       = Time.time + fireRate;                                              // Making sure player does not constantly fire
            StartCoroutine(ShotEffect(LlaserLine));                                             // Calling to able the line renderer
            StartCoroutine(ShotEffect(RlaserLine));                                             // Calling to able the line renderer
            Vector3 camShootingPoint = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0)); // Point where ray will shoot at

            RaycastHit hitObject;                                                               // Variable Raycast that will store the information of the object that is hit.

            // Setting initial starting position of te lasers to the tip of the designated wands.
            LlaserLine.SetPosition(0, LwandEnd.position);
            RlaserLine.SetPosition(0, RwandEnd.position);
            RamDepletion();


            // RayCast(origin, direction, out: inserting information of object hit from raycast, distance)
            if (Physics.Raycast(camShootingPoint, fpsCam.transform.forward, out hitObject, shootRange))
            {
                // Point stores the Vector3 transformation of the object hit in the game view
                LlaserLine.SetPosition(1, hitObject.point);
                RlaserLine.SetPosition(1, hitObject.point);

                //CALLING COMBO MATERIAL SWITCH
                //comboLaserMaterial(Lelement, Relement);

                // Bullet Cloning //
                bulletClone = Instantiate(bullet, hitObject.point, Quaternion.identity);
                Destroy(bulletClone, 0.2f);
                //print(hitObject.point);

                // Creating object of EnemyHealthDamageManager and inserting it with the hitObject
                enemyHealth = hitObject.collider.GetComponent <EnemyHealthAndDeathManager>();
                if (enemyHealth != null)
                {
                    // if it exsists, then insert wand damage
                    enemyHealth.DamageEnemy(wandDamage);
                    RamDepletion();
                }
            }
            else
            {
                // If a object is not hit, then just cast the laser line in forward direction pointing originating from the camera middle point
                LlaserLine.SetPosition(1, (camShootingPoint + (fpsCam.transform.forward * shootRange)));
                RlaserLine.SetPosition(1, (camShootingPoint + (fpsCam.transform.forward * shootRange)));
                RamDepletion();
                bulletClone = Instantiate(bullet, (camShootingPoint + (fpsCam.transform.forward * shootRange)), Quaternion.identity);
                Destroy(bulletClone, 0.2f);
            }
            // LlaserLine.material = lMaterialBase;
            // RlaserLine.material = rMaterialBase;
        }


        // Magic Switching System //



        // Q KEY: Left Wand //
        if (Input.GetKeyDown(KeyCode.Q) && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;
            if ((Lelement == "fire" && Relement == "ice") || (Lelement == "ice" && Relement == "fire"))
            {
                Lelement            = "lighting";
                LlaserLine.material = new Material(lightingMaterial);
                //print(Lelement);
            }
            else if ((Lelement == "lighting" && Relement == "ice") || (Lelement == "ice" && Relement == "lighting"))
            {
                Lelement            = "fire";
                LlaserLine.material = new Material(fireMaterial);
                // print(Lelement);
            }
            else if ((Lelement == "fire" && Relement == "lighting") || (Lelement == "lighting" && Relement == "fire"))
            {
                Lelement            = "ice";
                LlaserLine.material = new Material(iceMaterial);
                //print(Lelement);
            }
        }

        // E KEY: Right Wand //
        if (Input.GetKey(KeyCode.E) && Time.time > nextFire)
        {
            nextFire = Time.time + fireRate;
            if ((Lelement == "fire" && Relement == "ice") || (Lelement == "ice" && Relement == "fire"))
            {
                Relement            = "lighting";
                RlaserLine.material = new Material(lightingMaterial);
                //print(Relement);
            }
            else if ((Lelement == "lighting" && Relement == "ice") || (Lelement == "ice" && Relement == "lighting"))
            {
                Relement            = "fire";
                RlaserLine.material = new Material(fireMaterial);
                // print(Relement);
            }
            else if ((Lelement == "fire" && Relement == "lighting") || (Lelement == "lighting" && Relement == "fire"))
            {
                Relement            = "ice";
                RlaserLine.material = new Material(iceMaterial);
                // print(Relement);
            }
        }
        // Ram regeneration system //
        if (!(Input.GetButtonDown("Fire1") || Input.GetButtonDown("Fire2")) && (Time.time > nextRamFire) && IsRamPenalty == false)
        {
            nextRamFire = Time.time + ramFireRate;

            if (!(ramAmount == 100) || !(ramAmount > 100))
            {
                ramAmount += 5;
                if (ramAmount > 100)
                {
                    ramAmount = 100;
                }
                ramSlider.value = ramAmount;
            }
            else if (ramAmount > 100)
            {
                ramAmount       = 100;
                ramSlider.value = ramAmount;
            }
            // print(ramAmount);
        }

        // Ram penalty system //
        if (ramAmount == 0 || ramAmount < 0)
        {
            // print("Starting penalty");
            IsRamPenalty = true;
            StartPenalty();
        }
    } // end update