コード例 #1
0
 public void SelectTile(TileScript tile)
 {
     if (selectedSprite != null)
     {
         tile.ChangeSprite(selectedSprite.GetComponent <Image>().sprite);
     }
 }
コード例 #2
0
    protected virtual void movement(float horizInput)
    {
        if (!active)
        {
            return;
        }

        touchingGround = onGround;

        //Horizontal Movement
        if (Mathf.Abs(horizInput) > 0.75f && (canSmash || !seperateDashCooldown))
        {
            xSpeed += horizInput * Time.deltaTime * (Mathf.Abs(horizInput - xSpeed) > 0.1f ? turnSpeed : accelerate);
            spriteAnim.GetComponent <SpriteRenderer>().flipX = Mathf.Sign(horizInput) < 0.05f;
        }
        else
        {
            xSpeed = Mathf.Lerp(xSpeed, 0, Time.deltaTime * decelerate);
        }
        xSpeed = Mathf.Clamp(xSpeed, -speed, speed);
        slopeCheck();

        //Vertical Movement
        if (touchingGround)
        {
            canDoubleJump = true;

            if (Input.GetButtonDown("Jump" + playerControl) && (canSmash || !seperateDashCooldown || !tightDash))
            {
                rigid.velocity += (Vector2)transform.up * maxJumpHeight;
                audioManager.instance.Play(jump, 0.5f, UnityEngine.Random.Range(0.93f, 1.05f));
                Invoke("jumpDelay", 0.05f);
            }

            if (Input.GetAxis("Vertical" + playerControl) < -0.7f)
            {
                if (sqetch.animatedStretch < 0.5f)
                {
                    sqetch.setAnimatedStretch(0.5f);
                    if (!squishing)
                    {
                        squishing = true;
                        audioManager.instance.Play(squash, 0.4f, UnityEngine.Random.Range(0.9f, 1.1f));
                    }
                }
            }
            else
            {
                if (squishing)
                {
                    squishing = false;
                    audioManager.instance.Play(unsqaush, 0.4f, UnityEngine.Random.Range(0.9f, 1.1f));
                }
            }
            //dashingOnGround
            if (canDash && Input.GetButtonDown("Dash" + playerControl) && (canDashOnGround && canSmash))
            {
                StartCoroutine(dash(Input.GetAxis("Dash" + playerControl), true, true));
            }
        }
        else
        {
            if (canSmash)
            {
                if (Input.GetButtonDown("Jump" + playerControl) && doubleJump && canDoubleJump)
                {
                    canDoubleJump   = false;
                    rigid.velocity += (Vector2)transform.up * maxJumpHeight / 1.5f;
                    audioManager.instance.Play(jump, 0.5f, UnityEngine.Random.Range(0.93f, 1.05f));

                    GameObject dashExpurosion    = Instantiate(dashCancelParticle, transform.position, transform.rotation);
                    ParticleSystem.MainModule ps = dashExpurosion.GetComponent <ParticleSystem>().main;
                    ps.startColor = spriteAnim.GetComponent <SpriteRenderer>().color;
                    Destroy(dashExpurosion, 1.5f);
                }

                if (canDash && Input.GetButtonDown("Dash" + playerControl) && smashStateEnum == null)
                {
                    StartCoroutine(dash(Input.GetAxis("Dash" + playerControl), true, false));
                }

                if (Input.GetButtonDown("Smash" + playerControl) && smashStateEnum == null)
                {
                    smashStateEnum = chargeSmash(Input.GetAxis("Horizontal" + playerControl));
                    StartCoroutine(smashStateEnum);
                }
            }
        }

        //shortHop
        if (Input.GetButtonUp("Jump" + playerControl) && transform.InverseTransformDirection(rigid.velocity).y > minJumpHeight && jumped)
        {
            rigid.velocity = (Vector2)transform.up * minJumpHeight;
        }
        spriteAnimationManager(horizInput, touchingGround);
    }