]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Mouse/Stamping.cs
improved movement v0.1
[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     [SerializeField]
16     GameObject groundCheck;
17
18     [SerializeField]
19     GameObject dustEffect;
20
21     private bool isStamping = false;
22
23     // Start is called before the first frame update
24     void Start()
25     {
26         mouseController = GetComponent<MouseController>();
27         rb = GetComponent<Rigidbody2D>();
28     }
29
30     // Update is called once per frame
31     void Update()
32     {
33         if (!mouseController.isGrounded)
34         {
35             if (Input.GetKeyDown(KeyCode.S) || Input.GetKeyDown(KeyCode.DownArrow))
36             {
37                 isStamping = true;
38                 rb.velocity = Vector2.down * stampingSpeed;
39             }
40         }
41         else if (mouseController.isGrounded && isStamping)
42         {
43             isStamping = false;
44             Vector3 spawnPos = new Vector3(groundCheck.transform.position.x, groundCheck.transform.position.y + 1, groundCheck.transform.position.z);
45             Instantiate(dustEffect, spawnPos, Quaternion.identity);
46
47         }
48     }
49
50     private void OnCollisionEnter2D(Collision2D collision)
51     {
52         if (collision.gameObject.CompareTag("Stamp") && isStamping)
53         {
54             collision.gameObject.SetActive(false);
55         }
56     }
57 }