summaryrefslogtreecommitdiff
path: root/SurvivalTest/Assets/Scripts/Test/TestTopDown2DTransform.cs
blob: acfac6854b86266a1eddd12e4e96feb4258630be (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestTopDown2DTransform : MonoBehaviour
{
	public bool useGravity = false;

	public Vector3 position // x, y, h
	{
		get
		{
			Vector3 topdownPos = transform.position;
			topdownPos.y -= h;
			topdownPos.z = h;
			return topdownPos;
		}
		set
		{
			h = value.z;
			Vector3 realPos = transform.position;
			realPos.y = value.y + h;
			transform.position = realPos;
		}
	}

	public float x
	{
		get
		{
			return position.x;
		}
	}

	public float y
	{
		get
		{
			return position.y;
		}
	}

	public float h = 0;

	public float z
	{
		get
		{
			return transform.position.z; 
		}
	}

	public float depth
	{
		get
		{
			return this.z;
		}
	}

	private float vy = 0;

	private void Update()
	{
		if (useGravity)
		{
			Vector3 pos = position;
			vy += -9.8f * Time.deltaTime;
			pos.z = Mathf.Max(pos.z + vy * Time.deltaTime, 0f);
			if(pos.z == 0)
			{
				vy = 0;
			}
			position = pos;
		}
	}

}