-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransplantObject.cs
66 lines (59 loc) · 1.61 KB
/
TransplantObject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class TransplantObject : MonoBehaviour
{
Player player;
public Vector2Int moveToPos;
public bool holdPlayer;
public float fallTime;
public float fallDuration = .5f;
// Start is called before the first frame update
void Awake()
{
if (!player)
player = FindObjectOfType<Player>();
}
// Update is called once per frame
void Update()
{
if (holdPlayer)
{
if (Time.time > fallTime + fallDuration)
{
ReleasePlayer();
}
}
}
public void MoveObject(GameObject objToMove)
{
if (objToMove.GetComponent<Player>())
{
player.TransplantPlayer(moveToPos);
Cache.fadeToBlack.FadeOutScreen();
}
else if (objToMove.GetComponent<PushableTile>())
{
PushableTile push = objToMove.GetComponent<PushableTile>();
push.Transplant(moveToPos);
}
}
public void HoldPlayer()
{
holdPlayer = true;
player.canMove = false;
fallTime = Time.time;
}
public void ReleasePlayer()
{
holdPlayer = false;
player.canMove = true;
}
private void OnDrawGizmos()
{
Gizmos.color = Color.black;
Gizmos.DrawLine(transform.position + new Vector3(.5f, .5f, 0), moveToPos + new Vector2(.5f, .5f));
Gizmos.DrawCube(moveToPos + new Vector2(.5f, .5f), new Vector3(1, 1, 1));
}
}