You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.0 KiB
44 lines
1.0 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Level1
|
|
{
|
|
public class CarController : MonoBehaviour
|
|
{
|
|
public Transform target;
|
|
|
|
private void Awake()
|
|
{
|
|
//GameManager.StartGame += CarMove;
|
|
}
|
|
|
|
void CarMove()
|
|
{
|
|
Invoke("StartMove", Random.value * 2);
|
|
}
|
|
|
|
void StartMove()
|
|
{
|
|
StartCoroutine(MovePos(transform, target.position, 20f));
|
|
}
|
|
|
|
IEnumerator MovePos(Transform ts, Vector3 targetPos, float speed)
|
|
{
|
|
while (true)
|
|
{
|
|
yield return new WaitForFixedUpdate();
|
|
Vector3 moveDir = (targetPos - ts.position).normalized;
|
|
ts.position += moveDir * Time.fixedDeltaTime * speed;
|
|
if (Vector3.Distance(ts.position, targetPos) <= 1)
|
|
{
|
|
ts.position = targetPos;
|
|
yield break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|