Example #1
0
 // Update is called once per frame
 void Update()
 {
     if (!active)
     {
         anim.SetBool("Walking", false);
         return;
     }
     anim.SetBool("Walking", Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f);
     transform.Translate(Vector2.right * Input.GetAxis("Horizontal") * Time.deltaTime * speed);
     pawHitCooldownTimer -= Time.deltaTime;
     if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.2f)
     {
         transform.localScale = new Vector3((Input.GetAxis("Horizontal") < 0) ? 1 : -1, 1f, 1f);
     }
     if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.Z) || Input.GetKey(KeyCode.W))
     {
         if (CanJump())
         {
             Jump();
         }
     }
     if (Input.GetKey(KeyCode.Space) || Input.GetKey(KeyCode.X) || Input.GetKey(KeyCode.F))
     {
         if (pawHitCooldownTimer <= 0f)
         {
             pawHitCooldownTimer = pawHitCooldown;
             foreach (Collider2D other in Physics2D.OverlapCircleAll(paw.transform.position, pawSize))
             {
                 if (other.transform.tag == "Movable")
                 {
                     TilemapManager tmm    = other.transform.parent.GetComponent <TilemapManager>();
                     Vector2Int     boxPos = tmm.GetTilePosFromTransformPos(other.transform.position);
                     if (tmm.GetTilemap().PushBox(boxPos.x, boxPos.y, other.transform.position.x > transform.position.x))
                     {
                         GetComponent <AudioSource> ().clip = moveSound;
                         GetComponent <AudioSource> ().Play();
                     }
                     break;
                 }
             }
         }
     }
 }