예제 #1
0
    void Update()
    {
        bool heartbeating = false;

        maxsway         = EquippedWeapon.maxSway;
        minsway         = EquippedWeapon.minSway;
        totalbullets    = EquippedWeapon.TotalBullets;
        Damage          = EquippedWeapon.Damage + bonusDmg;
        FireRate        = EquippedWeapon.RateOfFire;
        bulletsinclip   = EquippedWeapon.BulletsInClip;
        projectile      = EquippedWeapon.bulletPrefab;
        Range           = EquippedWeapon.Range;
        shot            = EquippedWeapon.gunSound;
        bulletstoreload = (EquippedWeapon.bulletsincliplimit - EquippedWeapon.currentclip);
        looks.sprite    = EquippedWeapon.looks;
        shotpoint.transform.localPosition = EquippedWeapon.ShootingSpot;
        //WeaponSwitch
        if (/*switch it later to button*/ Input.GetButtonDown("Primary"))
        {
            src.PlayOneShot(pullout);
            EquippedWeapon = primary;
            if (hasBalaclava == true)
            {
                balaclava.transform.localPosition = new Vector3(0, 0.008f, 0);
            }
            Debug.Log("Primary" + EquippedWeapon.Name);
        }
        if (/*switch it later to button*/ Input.GetButtonDown("Secondary") && secondary != null && secondary.Type == "Weapon")
        {
            src.PlayOneShot(pullout);
            EquippedWeapon = secondary;
            if (hasBalaclava == true)
            {
                balaclava.transform.localPosition = new Vector3(0, 0.008f, 0);
            }
            Debug.Log("Secondary" + EquippedWeapon.Name);
        }
        else if (secondary == null || secondary.Type != "Weapon")
        {
            secondary      = null;
            EquippedWeapon = primary;
        }
        if (hasShield)
        {
            if (shields < HP && shieldloading == false)
            {
                shieldloading = true;
                StartCoroutine(giveshield());
            }
        }
        //use usable
        if (activeusable != null && dialogueon == false)
        {
            if (currentTimeActiveitem >= activeusable.regentime)
            {
                if (Input.GetKeyDown(KeyCode.Space))
                {
                    activeusable.OnUse();
                    currentTimeActiveitem = 0;
                }
            }
            else
            {
                currentTimeActiveitem += Time.deltaTime;
            }
        }//heart beating sound while 1HP
        if (!IsDead && HP == 1 && heartbeating == false)
        {
            if (src.isPlaying != true && !dialogueon)
            {
                src.clip = HeartBeat;
                src.loop = true;
                src.Play();
            }
        }
        else
        {
            src.clip = steps;
        }
        //rotation control
        if (!IsDead)
        {
            if (paused == false && dialogueon == false && MapOn == false)
            {
                Vector3 difference = cameramain.GetComponent <Camera>().ScreenToWorldPoint(Input.mousePosition) - transform.position;
                float   rotZ       = Mathf.Atan2(difference.y, difference.x) * Mathf.Rad2Deg;
                transform.rotation = Quaternion.Euler(0, 0, rotZ + offset);
            }
        }
        //Get Axes for movement
        if (IsDead != true && !isCutscene)
        {
            v    = Input.GetAxis("Vertical");
            h    = Input.GetAxis("Horizontal");
            Move = new Vector3(h, v, 0);
        }
        else
        {
            Move = new Vector3(0, 0, 0);
        }
        /////animation management
        if (Move.magnitude != 0)
        {
            legsanimator.SetBool("Walk", true);
            if (src.isPlaying == false)
            {
                if (IsDead == false && !paused && dialogueon == false && src.clip == steps && MapOn == false)
                {
                    src.loop = true;
                    src.clip = steps;
                    src.Play();
                }
            }
        }
        else if (Move.magnitude == 0)
        {
            legsanimator.SetBool("Walk", false);
            if (src.clip == steps)
            {
                src.clip = null;
            }
        }
        if (!IsDead)
        {
            if (paused == false && dialogueon == false && MapOn == false)
            {
                transform.Translate(Vector3.ClampMagnitude(Move, 1f) * Time.deltaTime * MoveSpeed, Space.World);
            }
        }
        if (inrangeToPickup == true && itemtopickup != null)
        {
            if ((itemtopickup.transform.position - this.gameObject.transform.position).magnitude <= 3 && itemtopickup.GetComponent <DropBehavior>().thisitem != null)
            {
                PickupText.SetActive(true);
                PickupText.transform.position             = itemtopickup.transform.position + new Vector3(0, 1, 0);
                PickupText.GetComponent <TextMesh>().text = "Press 'f' to pick up " + itemtopickup.GetComponent <DropBehavior>().thisitem.Name;
                PickupText.transform.eulerAngles          = new Vector3(0, 0, 0);
                if (Input.GetKeyDown(KeyCode.F))
                {
                    if ((transform.position - itemtopickup.transform.position).magnitude < 3)
                    {
                        Debug.Log("Pickup");
                        if (itemtopickup.GetComponent <DropBehavior>().thisitem.Type == "Weapon")
                        {
                            if (secondary != null)
                            {
                                drop(secondary);
                                secondary = (itemtopickup.GetComponent <DropBehavior>().thisitem as Weapon);
                                Destroy(itemtopickup);
                                src.PlayOneShot(pickupsound);
                            }
                            else
                            {
                                secondary = (itemtopickup.GetComponent <DropBehavior>().thisitem as Weapon);
                                Destroy(itemtopickup);
                                src.PlayOneShot(pickupsound);
                            }
                        }
                        else if (itemtopickup.GetComponent <DropBehavior>().thisitem.Type == "Usable")
                        {
                            if (activeusable != null)
                            {
                                drop(activeusable);
                                activeusable = (itemtopickup.GetComponent <DropBehavior>().thisitem as UsableItem);
                                Destroy(itemtopickup);
                                src.PlayOneShot(pickupsound);
                            }
                            else
                            {
                                activeusable = itemtopickup.GetComponent <DropBehavior>().thisitem as UsableItem;
                                Destroy(itemtopickup);
                                src.PlayOneShot(pickupsound);
                            }
                        }
                        else if (itemtopickup.GetComponent <DropBehavior>().thisitem.Type
                                 == "Passive")
                        {
                            Passive placehold = itemtopickup.GetComponent <DropBehavior>().thisitem as Passive;
                            placehold.OnPickup();

                            Destroy(itemtopickup);
                            placehold = null;
                        }
                    }
                }
            }
            else
            {
                inrangeToPickup = false; itemtopickup = null;
                PickupText.SetActive(false);
            }
        }
        else if (inrangeToPickup == false || itemtopickup == null)
        {
            PickupText.SetActive(false);
        }
        //die management
        if (HP <= 0)
        {
            Die();
        }
        //shooting management
        if (timeBtwShot <= 0)
        {
            if (!IsDead)
            {
                if (paused == false && dialogueon == false && MapOn == false)
                {
                    if (Input.GetButtonDown("Reload"))
                    {
                        StartCoroutine("Reload");
                    }
                    if (Input.GetButton("Fire1"))
                    {
                        if (EquippedWeapon.currentclip > 0)
                        {
                            if (Reloading == false)
                            {
                                if (!isCutscene)
                                {
                                    src.PlayOneShot(shot);

                                    sprayRotation = Random.Range(minsway, maxsway);
                                    Instantiate(projectile, shotpoint.position, transform.rotation * Quaternion.Euler(0, 0, sprayRotation));
                                    Instantiate(particles, shotpoint.position, transform.rotation);
                                    EquippedWeapon.currentclip--;
                                    timeBtwShot = FireRate;
                                    camAnim.SetTrigger("Shake");
                                }
                            }
                        }
                        else if (EquippedWeapon.currentclip <= 0 && EquippedWeapon.TotalBullets >= 0)
                        {
                            StartCoroutine("Reload");
                        }
                        else
                        {
                            //do nothing
                        }
                    }
                }
            }
        }

        else
        {
            timeBtwShot -= Time.deltaTime;
        }

        /*  if (Input.GetButtonDown("Fire1") && Reloading == false)
         * {
         *    isshooting = true;
         * }
         * if (Input.GetButtonUp("Fire1"))
         * {
         *    isshooting = false;
         * }
         * if (isshooting == true)
         * {
         *    if (!shells.isPlaying && Reloading == false)
         *    {
         *       var emission = shells.emission;
         *        emission.rateOverTime =1/EquippedWeapon.RateOfFire;
         *       // shells.maxParticles =;
         *        shells.Play();
         *
         *    }
         *
         * }
         * else*/
        {
            shells.Stop();
        }
    }