summaryrefslogtreecommitdiff
path: root/AlienSurvival/Assets/Test/Scripts/TestFakeHeight.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2022-04-16 16:20:20 +0800
committerchai <chaifix@163.com>2022-04-16 16:20:20 +0800
commit6cf30c620615508705e2e800c04eebb7a45e6e04 (patch)
tree7383063f55f9709a5d9fb55caa1b37ad02a7cc11 /AlienSurvival/Assets/Test/Scripts/TestFakeHeight.cs
parent67eb78bc7820f189b60da157dddea1ec16ade65a (diff)
+ plant test
Diffstat (limited to 'AlienSurvival/Assets/Test/Scripts/TestFakeHeight.cs')
-rw-r--r--AlienSurvival/Assets/Test/Scripts/TestFakeHeight.cs86
1 files changed, 80 insertions, 6 deletions
diff --git a/AlienSurvival/Assets/Test/Scripts/TestFakeHeight.cs b/AlienSurvival/Assets/Test/Scripts/TestFakeHeight.cs
index 06fe545..35174a5 100644
--- a/AlienSurvival/Assets/Test/Scripts/TestFakeHeight.cs
+++ b/AlienSurvival/Assets/Test/Scripts/TestFakeHeight.cs
@@ -4,11 +4,85 @@ using UnityEngine;
public class TestFakeHeight : MonoBehaviour
{
- [SerializeField]
- private float m_Height; // fake height
-
- void Update()
+ [SerializeField] private Transform m_Shadow;
+
+ public float height { get { return m_Height; } set { m_Height = value; } }
+ [SerializeField] private float m_Height; // current fake height
+
+ public float x
+ {
+ get
+ {
+ return transform.position.x;
+ }
+
+ set
+ {
+ Vector3 pos = transform.position;
+ pos.x = value;
+ transform.position = pos;
+ }
+ }
+
+ public float y
+ {
+ get
+ {
+ return transform.position.y - m_Height;
+ }
+ set
+ {
+ Vector3 pos = transform.position;
+ pos.y = value + m_Height;
+ transform.position = pos;
+ }
+ }
+
+ public Vector3 position
+ {
+ get
+ {
+ Vector3 pos = new Vector3(x, y, height);
+ return pos;
+ }
+ }
+
+ public Vector2 positionOnGround
+ {
+ get
+ {
+ Vector2 pos = new Vector2(x, y);
+ return pos;
+ }
+ set
+ {
+ x = value.x;
+ y = value.y;
+ }
+ }
+
+ private float m_PreHeight;
+
+ private SpriteRenderer m_SpriteRenderer;
+
+ private void OnEnable()
+ {
+ m_SpriteRenderer = GetComponent<SpriteRenderer>();
+ m_PreHeight = m_Height;
+ }
+
+ void Update()
{
-
- }
+ Vector3 pos = transform.position;
+
+ pos.y = pos.y - m_PreHeight + m_Height;
+ transform.position = pos;
+
+ m_Shadow.position = new Vector3(transform.position.x, transform.position.y - m_Height, transform.position.z);
+
+ m_PreHeight = m_Height;
+
+ // ¸ù¾ÝyÉèÖÃsortOrder
+ m_SpriteRenderer.sortingOrder =(int) (-y * 100);
+ }
}