37 lines
949 B
C#
37 lines
949 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class MoveObjectOverTimeTrigger : MonoBehaviour
|
|
{
|
|
[SerializeField] private Transform _object;
|
|
[SerializeField] private Transform endPosition;
|
|
[SerializeField] private float speed;
|
|
|
|
private bool _hasMoved;
|
|
|
|
private void OnTriggerEnter(Collider col)
|
|
{
|
|
if (col.gameObject.tag == "Player" && !_hasMoved)
|
|
{
|
|
StartCoroutine(MoveObject());
|
|
_hasMoved = true;
|
|
}
|
|
}
|
|
|
|
IEnumerator MoveObject()
|
|
{
|
|
while (_object.position != endPosition.position)
|
|
{
|
|
MoveObjectForward();
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
public void MoveObjectForward()
|
|
{
|
|
_object.transform.localPosition = Vector3.MoveTowards(_object.transform.localPosition, endPosition.localPosition, speed * Time.deltaTime);
|
|
print("Is moving object to new pos");
|
|
}
|
|
}
|