Tanoda
CardPopup2D.cs
Go to the documentation of this file.
1
5
6using System.Collections;
7using System.Collections.Generic;
8using UnityEngine;
9
11{
12
13[RequireComponent(typeof(Rigidbody))]
14public class CardPopup2D : MonoBehaviour
15{
16 [SerializeField]
17 private float rotationSpeed = 1f;
18 [SerializeField]
19 private float centeringSpeed = 4f;
20 [SerializeField]
21 private bool singleScene = false;
22
23 private Rigidbody rbody;
24 private bool isFalling;
25 private Vector3 cardFallRotation;
26 private bool fallToZero;
27 private float startZPos;
28
29 void Start()
30 {
31 rbody = GetComponent<Rigidbody>();
32 rbody.useGravity = false;
33 startZPos = transform.position.z;
34 }
35
36 void Update()
37 {
38 if (isFalling)
39 {
40 transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(cardFallRotation), Time.deltaTime * rotationSpeed);
41 }
42
44 if (fallToZero)
45 {
46 transform.position = Vector3.Lerp(transform.position, new Vector3(0, 0, startZPos), Time.deltaTime * centeringSpeed);
47 transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(Vector3.zero), Time.deltaTime * centeringSpeed);
48 if (Vector3.Distance(transform.position, new Vector3(0, 0, startZPos)) < 0.0025f)
49 {
50 transform.position = new Vector3(0, 0, startZPos);
51 fallToZero = false;
52 }
53 }
54
56 if (transform.position.y < -4)
57 {
58 isFalling = false;
59 rbody.useGravity = false;
60 rbody.velocity = Vector3.zero;
61 transform.position = new Vector3(0, 8, startZPos);
62 if (singleScene)
63 {
64 CardEnter();
65 }
66 }
67 }
68
69 public void CardEnter()
70 {
71 fallToZero = true;
72 }
73
75 public void CardFallAway(float fallRotation)
76 {
77 rbody.useGravity = true;
78 isFalling = true;
79 cardFallRotation = new Vector3(0, 0, fallRotation);
80 }
81}
82}
void CardFallAway(float fallRotation)
A negative fallRotation will result in the card turning clockwise, while a positive fallRotation make...
Definition: CardPopup2D.cs:75
Credit Erdener Gonenc - @PixelEnvision.