예제 #1
0
    // Update is called once per frame
    void Update()
    {
        if (!dnf && fin.HasBegun())
        {
            this.GetComponent <Animator> ().SetBool("grounded", grounded);
            this.GetComponent <Animator> ().SetBool("crashed", crashed);
            this.GetComponent <Animator> ().SetBool("inBush", inBush);
            this.GetComponent <Animator> ().SetBool("inWater", inWater);

            Vector3 viewPos = Camera.main.WorldToViewportPoint(this.transform.position);

            if (viewPos.x <= 0.1f)
            {
                speedMod = Mathf.Lerp(speedMod, pc.GetLeader().GetComponent <HorseController> ().GetSpeedMod(), Time.deltaTime * 0.5f);
            }
            if (viewPos.x <= -0.1f && callOnce)
            {
                OutOfBounds();
            }
            //this.transform.position = new Vector3 (Camera.main.transform.position.x, this.transform.position.y, this.transform.position.z);
            if (viewPos.x >= 0)
            {
                callOnce = true;
            }

            if (!crashed)
            {
                //StopCoroutine (waitFor (2));

                if (grounded)
                {
                    ParticleSystemExtension.SetEmissionRate(ps, speed * 50);
                    if (speed > 0.25)
                    {
                        GetComponent <AudioSource> ().mute = false;
                    }
                    else
                    {
                        GetComponent <AudioSource> ().mute = true;
                    }
                }
                else
                {
                    ParticleSystemExtension.SetEmissionRate(ps, 0);
                    GetComponent <AudioSource> ().mute = true;
                }

                if (Input.GetButton(this.name))
                {
                    speedInp -= Time.deltaTime;
                }
                if (Input.GetButtonUp(this.name))
                {
                    if (speedInp <= 0.9f)
                    {
                        speedMod += (speedInp * 1.25f);
                    }
                    speedInp = 1;
                }
                if (Input.GetAxis(this.name) < 0)
                {
                    jumpInp += Time.deltaTime;
                }
                else
                {
                    jumpInp = 0;
                }

                speedMod -= 1.5f * Time.deltaTime;
                //stamina += 10 * Time.deltaTime * (1 + pc.GetLead (this.transform) / 10);

                speed = (speedMod / 5) * slowValue * baseMoveMod * Time.deltaTime * (pc.GetLead(this.transform) / 10 + 1);
                this.GetComponent <Animator> ().SetFloat("speed", speed);

                this.transform.position += new Vector3(speed / 10, 0, 0);
                if (!Input.GetButton(this.name + " Jump") && grounded && !jumpOnce)
                {
                    this.GetComponent <Rigidbody2D> ().AddForce(jumpForce);
                    jumpOnce = true;
                    //stamina -= 10;
                    //grounded = false;
                }
                if (Input.GetButtonDown(this.name + " Jump"))
                {
                    jumpOnce = false;
                }

                //if (stamina <= 10)
                //crashed = true;
            }
            else if (crashed)
            {
                speedMod -= Time.deltaTime * 50;
                //stamina -= 10 * Time.deltaTime;
                //StartCoroutine (waitFor (3));
                //if (!callOnce) {
                //	speedMod = speedMod / 4;
                //	callOnce = true;
                //}
            }

            speedInp = Mathf.Clamp(speedInp, 0, 1);
            speedMod = Mathf.Clamp(speedMod, 0.025f, 100);
            speed    = Mathf.Clamp(speed, 0.025f, 100);

            this.GetComponent <Animator> ().SetBool("grounded", grounded);
            this.GetComponent <Animator> ().SetBool("crashed", crashed);
            this.GetComponent <Animator> ().SetBool("inBush", inBush);
            this.GetComponent <Animator> ().SetBool("inWater", inWater);
            //stamina = Mathf.Clamp (stamina, 0, 100);

            //staminaBar.value = stamina;
            //staminaBar.transform.position = new Vector3 (this.transform.position.x, this.transform.position.y + 1, 0);
        }
    }