Ejemplo n.º 1
0
 private void InitializeStats()
 {
     foreach (Equipment eq in PlayerManager.instance.equipment)
     {
         if (eq is WeaponEquipment)
         {
             WeaponEquipment     w  = eq as WeaponEquipment;
             WeaponUpgradeStruct wu = new WeaponUpgradeStruct(800, 1, w.damage, w.inaccuracy, w.fireRate, w.range);
             wu.Upgrade();
             upgradeStructs.Add(wu);
             structVals.Add(0);
         }
         else if (eq is StorageEquipment)
         {
             StorageEquipment     s  = eq as StorageEquipment;
             StorageUpgradeStruct su = new StorageUpgradeStruct(700, 1, s.capacity);
             su.Upgrade();
             upgradeStructs.Add(su);
             structVals.Add(1);
         }
         else if (eq is EnergyEquipment)
         {
             EnergyEquipment     e  = eq as EnergyEquipment;
             EnergyUpgradeStruct ee = new EnergyUpgradeStruct(850, 1, e.energyCapacity);
             ee.Upgrade();
             upgradeStructs.Add(ee);
             structVals.Add(2);
         }
         else if (eq is TransmitterEquipment)
         {
             TransmitterEquipment t  = eq as TransmitterEquipment;
             TransUpgradeStruct   tu = new TransUpgradeStruct(700, 1, t.uploadFactor);
             tu.Upgrade();
             upgradeStructs.Add(tu);
             structVals.Add(3);
         }
         else
         {
             ResearchEquipment     r  = eq as ResearchEquipment;
             ResearchUpgradeStruct ru = new ResearchUpgradeStruct(750, 1, r.scanTime, r.range);
             ru.Upgrade();
             upgradeStructs.Add(ru);
             structVals.Add(4);
         }
     }
 }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (!isEnabled)
        {
            return;
        }
        if (!isAi)
        {
            //rotation
            transform.Rotate(Vector3.up * Input.GetAxisRaw("Horizontal") * Time.deltaTime * rotationSpeed);
            //if (Input.GetAxis("Horizontal") > 0)
            //{
            //    frontRightWheelTransform.localRotation = Quaternion.Slerp(frontRightMinRotation, frontRightMaxRotation, Input.GetAxis("Horizontal"));
            //    frontLeftWheelTransform.localRotation = Quaternion.Slerp(frontLeftMaxRotation, frontLeftMinRotation, Input.GetAxis("Horizontal"));
            //}
            //else if (Input.GetAxis("Horizontal") < 0)
            //{
            //    frontRightWheelTransform.localRotation = Quaternion.Slerp(frontRightMaxRotation, frontRightMinRotation, Input.GetAxis("Horizontal"));
            //    frontLeftWheelTransform.localRotation = Quaternion.Slerp(frontLeftMinRotation, frontLeftMaxRotation, Input.GetAxis("Horizontal"));
            //}
            //else
            //{
            //    frontRightWheelTransform.localRotation = frontRightBaseRotation;
            //    frontLeftWheelTransform.localRotation = frontLeftBaseRotation;
            //}
            //frontRightWheelTransform.localRotation = Quaternion.Slerp(frontRightMinRotation,frontRightMaxRotation, Input.GetAxis("Horizontal"));
            //frontLeftWheelTransform.localRotation = Quaternion.Slerp(frontLeftMinRotation, frontLeftMaxRotation, Input.GetAxis("Horizontal"));
            if (Input.GetAxisRaw("Horizontal") == 1f)
            {
                frontRightWheelTransform.localRotation = Quaternion.Slerp(frontRightWheelTransform.localRotation, frontRightMaxRotation, Time.deltaTime * 20f);
                frontLeftWheelTransform.localRotation  = Quaternion.Slerp(frontLeftWheelTransform.localRotation, frontLeftMinRotation, Time.deltaTime * 20f);
            }
            else if (Input.GetAxisRaw("Horizontal") == -1f)
            {
                //frontRightWheelTransform.localRotation = frontRightMinRotation;
                //frontLeftWheelTransform.localRotation = frontLeftMaxRotation;
                frontRightWheelTransform.localRotation = Quaternion.Slerp(frontRightWheelTransform.localRotation, frontRightMinRotation, Time.deltaTime * 20f);
                frontLeftWheelTransform.localRotation  = Quaternion.Slerp(frontLeftWheelTransform.localRotation, frontLeftMaxRotation, Time.deltaTime * 20f);
            }
            else
            {
                frontRightWheelTransform.localRotation = Quaternion.Slerp(frontRightWheelTransform.localRotation, frontRightBaseRotation, Time.deltaTime * 20f);
                frontLeftWheelTransform.localRotation  = Quaternion.Slerp(frontLeftWheelTransform.localRotation, frontLeftBaseRotation, Time.deltaTime * 20f);
                //frontRightWheelTransform.localRotation = frontRightBaseRotation;
                //frontLeftWheelTransform.localRotation = frontLeftBaseRotation;
            }

            //movement
            Vector3 moveDir          = new Vector3(0, 0, Input.GetAxisRaw("Vertical")).normalized;
            Vector3 targetMoveAmount = moveDir * moveSpeed;
            moveAmount = Vector3.SmoothDamp(moveAmount, targetMoveAmount, ref smoothMoveVelocity, movementSmoothTime);

            if (Input.GetAxisRaw("Vertical") == 1)
            {
                foreach (Transform wheel in WheelTransforms)
                {
                    wheel.RotateAround(wheel.position, transform.right, 5f);
                }
            }
            else if (Input.GetAxisRaw("Vertical") == -1)
            {
                foreach (Transform wheel in WheelTransforms)
                {
                    wheel.RotateAround(wheel.position, transform.right, -5f);
                }
            }

            //research material interaction
            if (Input.GetKeyDown(KeyCode.Q))
            {
                if (!isTransmittingData)
                {
                    CheckForNearbyResearchMaterial();
                }
                else
                {
                    Debug.Log("Can't scan while transmitting data");
                }
            }

            //transmit research data to mission control
            if (Input.GetKeyDown(KeyCode.E))
            {
                TransmitterEquipment transmitter = (TransmitterEquipment)PlayerManager.instance.equipment[1];
                transmitter.TransmitResearchData();
            }

            // Weapon functionality
            if (hasWeapon)
            {
                weapon.Rotate();

                if (Input.GetMouseButton(0))
                {
                    if (enter == false)
                    {
                        StartCoroutine(timer(weapon.fireRate));
                        weaponFx.Play();
                        weapon.Shoot();
                    }
                }
            }
        }
        else
        {
            // check for landing pods if there is at least one landing pod on the planet
            if (PlayerManager.instance.GetComponent <LandingPodSpawner>().currentPods.Count > 0)
            {
                Collider[] nearbyLandingPods = Physics.OverlapSphere(transform.position, 3f, landingPodLayerMask);
                //if we are not near a landing pod, then go towards one
                if (nearbyLandingPods.Length == 0)
                {
                    if (PlayerManager.instance.nearbyEnergyArrowAngle != -10000f)
                    {
                        if (PlayerManager.instance.nearbyEnergyArrowAngle < -5f)
                        {
                            //turn right
                            transform.Rotate(Vector3.up * 0.8f * Time.deltaTime * rotationSpeed);
                        }
                        else if (PlayerManager.instance.nearbyEnergyArrowAngle > 5f)
                        {
                            //turn left
                            transform.Rotate(Vector3.up * -0.8f * Time.deltaTime * rotationSpeed);
                        }
                    }
                    //move forward
                    Vector3 moveDir          = new Vector3(0, 0, 1f).normalized;
                    Vector3 targetMoveAmount = moveDir * moveSpeed;
                    moveAmount = Vector3.SmoothDamp(moveAmount, targetMoveAmount, ref smoothMoveVelocity, movementSmoothTime);
                }
                else
                {
                    //don't move since we're refueling at landing pod
                    moveAmount = Vector3.zero;
                }
            }
            else
            {
                //start scanning to try to collect research materials
                if (!isTransmittingData)
                {
                    CheckForNearbyResearchMaterial();
                }
                //move forward
                Vector3 moveDir          = new Vector3(0, 0, 1f).normalized;
                Vector3 targetMoveAmount = moveDir * moveSpeed;
                moveAmount = Vector3.SmoothDamp(moveAmount, targetMoveAmount, ref smoothMoveVelocity, movementSmoothTime);
            }
            if (hasWeapon)
            {
                Collider[] nearbyAliens = Physics.OverlapSphere(transform.position, aiShootMaxRange, alienLayerMask);
                if (nearbyAliens.Length > 0)
                {
                    Vector3 directionToAlien   = (nearbyAliens[0].transform.position - weaponTransform.position).normalized;
                    Vector3 projectedDirection = Vector3.ProjectOnPlane(directionToAlien, weaponTransform.forward).normalized;
                    float   angleDifference    = Vector3.Angle(-weaponTransform.up, projectedDirection);
                    if (angleDifference > 2f)
                    {
                        //rotate weapon
                        weapon.Rotate(1f);
                    }
                    else if (angleDifference < -2f)
                    {
                        //rotate weapon
                        weapon.Rotate(-1f);
                    }
                    else
                    {
                        //shoot
                        if (enter == false)
                        {
                            StartCoroutine(timer(weapon.fireRate));
                            weaponFx.Play();
                            weapon.Shoot();
                        }
                    }
                }
            }
        }

        //if scanning, update scan effect
        if (sampleCollectionsLeft > 0)
        {
            scanRange += scanSpeed * Time.deltaTime;
            if (scanRange > scanMaxRange)
            {
                scanRange = 0f;
            }
            scanTransform.localScale = new Vector3(scanRange, scanRange);
        }
    }