|
@ -8,16 +8,32 @@ public class PlatformMover : MonoBehaviour |
|
|
[SerializeField] private Transform m_EndPos; |
|
|
[SerializeField] private Transform m_EndPos; |
|
|
[SerializeField] private float m_Duration = 2f; |
|
|
[SerializeField] private float m_Duration = 2f; |
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
|
void Start() |
|
|
|
|
|
|
|
|
private Transform m_OldParent; |
|
|
|
|
|
|
|
|
|
|
|
private void Update() |
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
transform.position = Vector2.Lerp(m_StartPos.position, m_EndPos.position, (Mathf.Sin(Time.time * m_Duration) + 1.0f) / 2.0f); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
|
void Update() |
|
|
|
|
|
|
|
|
private void OnCollisionEnter2D(Collision2D collision) |
|
|
{ |
|
|
{ |
|
|
transform.position = Vector2.Lerp(m_StartPos.position, m_EndPos.position, (Mathf.Sin(Time.time * m_Duration) + 1.0f) / 2.0f); |
|
|
|
|
|
|
|
|
var playerController = collision.gameObject.GetComponent<CharacterController2D>(); |
|
|
|
|
|
if(playerController) |
|
|
|
|
|
{ |
|
|
|
|
|
m_OldParent = playerController.transform.parent; |
|
|
|
|
|
playerController.transform.parent = transform; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void OnCollisionExit2D(Collision2D collision) |
|
|
|
|
|
{ |
|
|
|
|
|
var playerController = collision.gameObject.GetComponent<CharacterController2D>(); |
|
|
|
|
|
if(playerController) |
|
|
|
|
|
{ |
|
|
|
|
|
playerController.transform.parent = m_OldParent; |
|
|
|
|
|
m_OldParent = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
#if UNITY_EDITOR
|
|
|