]> git.lizzy.rs Git - SuperMouseAdventure.git/blob - 2DGame/Assets/Scripts/Mouse/Scissors.cs
Verbesserte Kamera und verbessertes Level-Design
[SuperMouseAdventure.git] / 2DGame / Assets / Scripts / Mouse / Scissors.cs
1 using System;
2 using System.Collections;
3 using System.Collections.Generic;
4 using UnityEngine;
5
6 public class Scissors : MonoBehaviour
7 {
8     [SerializeField]
9     float speed;
10
11     [SerializeField]
12     float lifeTime;
13
14     public void StartShoot(bool isFacingLeft, Vector2 velocity)
15     {
16         Rigidbody2D rb2d = GetComponent<Rigidbody2D>();
17         transform.localScale = new Vector3(0.4f, 0.4f, 1);
18
19         if (isFacingLeft == true)
20         {
21             rb2d.velocity = new Vector2(-speed, 0) + velocity;
22         }
23         else
24         {
25             rb2d.velocity = new Vector2(speed, 0) + velocity;
26         }
27
28         Vector2 movementDirection = rb2d.velocity;
29                 movementDirection.Normalize();
30                 transform.rotation = Quaternion.LookRotation(Vector3.forward, movementDirection) * Quaternion.Euler(0, 0, 90);
31
32         Destroy(gameObject, lifeTime);
33     }
34
35     private void OnCollisionEnter2D(Collision2D collision)
36     {
37         if (collision.gameObject.CompareTag("Thorn"))
38         {
39             collision.gameObject.SetActive(false);
40             Destroy(gameObject);
41         }
42         else
43         {
44             Destroy(gameObject);
45         }
46     }
47 }