]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Mouse/Stamping.cs
0f1160bf4a9b9ee959be7ab755c4e095ad21c376
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Mouse / Stamping.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using UnityEngine;
5 using UnityEngine.Tilemaps;
6
7 public class Stamping : MonoBehaviour
8 {
9     MouseController mouseController;
10     Rigidbody2D rb;
11
12     [SerializeField]
13     private float stampingSpeed = 40;
14
15     private bool isStamping = false;
16
17     // Start is called before the first frame update
18     void Start()
19     {
20         mouseController = GetComponent<MouseController>();
21         rb = GetComponent<Rigidbody2D>();
22     }
23
24     // Update is called once per frame
25     void Update()
26     {
27         if (!mouseController.isGrounded)
28         {
29             if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
30             {
31                 isStamping = true;
32                 rb.velocity = Vector2.down * stampingSpeed;
33             }
34         }
35         else if (mouseController.isGrounded)
36         {
37             isStamping = false;
38         }
39     }
40
41     private void OnCollisionEnter2D(Collision2D collision)
42     {
43         if (collision.gameObject.CompareTag("Stamp") && isStamping)
44         {
45             collision.gameObject.SetActive(false);
46         }
47     }
48 }