// Update is called once per frame
    void Update()
    {
        if (ourOwner.isWormActive())
        {
            //Checks if G is pressed and that the team's inventory has a grenade
            if (Input.GetKey(KeyCode.G) && (myTeamInventory.getGrenades() > 0))
            {
                if (GrenadeDisplayTest)  // grenade strength being calculated
                {
                    GrenadeDisplayTest.setDisplay(((int)(strengthMeter.relativePercentage())).ToString());

                    //strengthMeterDisplay.transform.localPosition += 0.5f * Vector3.up;                    I tried to make the grenade strength meter go above the health but i think ill just go for hiding the health and making it re-appear
                    // strengthMeterDisplay.transform.position += 0.5f * Vector3.up;
                    if (strengthMeter.relative() > 1.0f)
                    {
                        createGrenade();
                    }
                }
                else   // Start of launch grenade
                {
                    GrenadeDisplayTest = gameObject.AddComponent <PowerDisplay>();
                    strengthMeter      = gameObject.AddComponent <TimeAndDisplayCountup>();
                    strengthMeter.setDuration(5.0f);
                    strengthMeter.startTimer();
                    //strengthMeterDisplay.transform.localPosition = 2.5f * Vector3.up;
                }
            }

            else if (myTeamInventory.getGrenades() == 0)
            {
                Debug.Log("No Grenades in Inventory (P to add)");
            }

            else
            {
                if (strengthMeter)

                {
                    createGrenade();
                }
            }


            if (Input.GetKey(KeyCode.M))
            {
                if (ourAimCam)
                {
                    print("Camera made");
                    ourAimCam.updateHorizontalAngle(Input.GetAxis("Horizontal"));
                    ourAimCam.updateVerticalAngle(Input.GetAxis("Vertical"));

                    if (crosshairs)
                    {
                        crosshairs.transform.position = ourAimCam.target;
                    }
                    if (Input.GetMouseButtonDown(0))
                    {
                        GameObject        newProjectileGO     = (GameObject)Instantiate(grenadePrefab);
                        ProjectileControl newProjectileScript = newProjectileGO.GetComponent <ProjectileControl>();

                        newProjectileScript.youAreA(ProjectileControl.ProjectileType.Missile, ourAimCam.transform.position, (ourAimCam.target - ourAimCam.transform.position).normalized, 15.0f, ExplosionPrefab, ourOwner);
                        DestroyAimCam();
                        //   ourOwner.setActive(false);
                    }
                }

                else
                {
                    print("Adding Aim Camera");
                    GameObject cam = new GameObject("Aiming Camera");
                    cam.AddComponent <Camera>();

                    ourAimCam = cam.gameObject.AddComponent <AimCameraControl>();

                    ourAimCam.transform.position = transform.position + 2.0f * Vector3.up - 2.0f * transform.forward;
                    ourAimCam.transform.rotation = transform.rotation;
                    ourAimCam.target             = transform.position + 50 * transform.forward;


                    crosshairs    = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                    firingMissile = true;
                }
            }

            else  // M released (or not pressed)
            {
                if (firingMissile)
                {
                    Destroy(ourAimCam.gameObject);
                    Destroy(crosshairs);
                    firingMissile = false;
                }
            }


            //Fire Bullet
            if (Input.GetKey(KeyCode.F))
            {
                if (ourAimCam)
                {
                    ourAimCam.transform.Rotate(Vector3.up, Input.GetAxis("Horizontal"));
                    ourAimCam.transform.Rotate(transform.right, Input.GetAxis("Vertical"));
                    if (crosshairs)
                    {
                        crosshairs.transform.position = ourAimCam.transform.position + 50.0f * ourAimCam.transform.forward;
                    }
                    if (Input.GetMouseButtonDown(0))
                    {
                        Debug.DrawRay(ourAimCam.transform.position, ourAimCam.transform.forward * 1000, Color.blue, 10.0f);
                        Ray        bullets = new Ray(ourAimCam.transform.position, ourAimCam.transform.forward);
                        RaycastHit info    = new RaycastHit();

                        if (Physics.Raycast(bullets, out info))
                        {
                            Health healthOfVictim = info.collider.GetComponent <Health>();
                            if (healthOfVictim)
                            {
                                healthOfVictim.adjustHealth(-20);
                            }
                        }



                        DestroyAimCam();
                        ourOwner.setActive(false);
                    }
                }

                else
                {
                    GameObject cam = new GameObject("Bullet Camera");
                    cam.AddComponent <Camera>();
                    ourAimCam = cam.gameObject.AddComponent <AimCameraControl>();

                    ourAimCam.transform.position = transform.position + 2.0f * Vector3.up - 2.0f * transform.forward;
                    ourAimCam.transform.rotation = transform.rotation;

                    crosshairs = GameObject.CreatePrimitive(PrimitiveType.Cylinder);

                    firingBullet = true;
                }
            }

            else  // F released (or not pressed)
            {
                if (firingBullet)
                {
                    firingBullet = false;
                    Destroy(ourAimCam.gameObject);
                    Destroy(crosshairs);
                }
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (ourOwner.isWormActive())
        {
            if (Input.GetKey(KeyCode.G))
            {
                //Checks that the player inventory has a grenade
                //if (player.allTeams[player.current_Team_Index].teamInventory.getGrenades() > 0)
                //{

                if (GrenadeDisplayTest)  // grenade strength being calculated
                {
                    GrenadeDisplayTest.setDisplay(((int)(strengthMeter.relativePercentage())).ToString());

                    //strengthMeterDisplay.transform.localPosition += 0.5f * Vector3.up;                    I tried to make the grenade strength meter go above the health but i think ill just go for hiding the health and making it re-appear
                    // strengthMeterDisplay.transform.position += 0.5f * Vector3.up;
                    if (strengthMeter.relative() > 1.0f)
                    {
                        createGrenade();
                    }
                }
                else   // STart of launch grenade
                {
                    GrenadeDisplayTest = gameObject.AddComponent <PowerDisplay>();
                    strengthMeter      = gameObject.AddComponent <TimeAndDisplayCountup>();
                    strengthMeter.setDuration(5.0f);
                    strengthMeter.startTimer();
                    //strengthMeterDisplay.transform.localPosition = 2.5f * Vector3.up;
                }

                //}

                //Removes a grenade from the inventory
                //player.allTeams[player.current_Team_Index].teamInventory.removeGrenades(1);

                //}
                //else
                //{
                //Debug.Log("No Grenades in Inventory (P to add)");
                //}
            }

            else
            {
                if (strengthMeter)

                {
                    createGrenade();
                }
            }


            if (Input.GetKey(KeyCode.M))
            {
                if (ourAimCam)
                {
                    ourAimCam.transform.Rotate(Vector3.up, Input.GetAxis("Horizontal"));
                    ourAimCam.transform.Rotate(transform.right, Input.GetAxis("Vertical"));
                    if (crosshairs)
                    {
                        crosshairs.transform.position = ourAimCam.transform.position + 50.0f * ourAimCam.transform.forward;
                    }
                    if (Input.GetMouseButtonDown(0))
                    {
                        GameObject        newProjectileGO     = (GameObject)Instantiate(grenadePrefab);
                        ProjectileControl newProjectileScript = newProjectileGO.GetComponent <ProjectileControl>();

                        newProjectileScript.youAreA(ProjectileControl.ProjectileType.Missile, ourAimCam.transform.position, ourAimCam.transform.forward, 15.0f, ourOwner);
                        DestroyAimCam();
                        ourOwner.setActive(false);
                    }
                }

                else
                {
                    GameObject cam = new GameObject();
                    cam.AddComponent <Camera>();
                    ourAimCam = cam.gameObject.AddComponent <AimCameraControl>();

                    ourAimCam.transform.position = transform.position + 2.0f * Vector3.up - 2.0f * transform.forward;
                    ourAimCam.transform.rotation = transform.rotation;

                    crosshairs = GameObject.CreatePrimitive(PrimitiveType.Sphere);
                }
            }

            else  // M released (or not pressed)
            {
                if (ourAimCam)
                {
                    Destroy(ourAimCam.gameObject);
                    Destroy(crosshairs);
                }
            }
        }
    }