41 lines
777 B
C#
41 lines
777 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class MoveableVehicle : MovableObject
|
|
{
|
|
public bool shouldStop;
|
|
public float stopTime;
|
|
private bool isStopped = false;
|
|
|
|
protected override void Initialize()
|
|
{
|
|
shouldStop = Random.value > 0.5f; // 50% 概率停留
|
|
stopTime = Random.Range(1f, 3f);
|
|
}
|
|
|
|
|
|
protected override void Update()
|
|
{
|
|
if (!isStopped)
|
|
{
|
|
Move();
|
|
}
|
|
}
|
|
|
|
private IEnumerator StopCoroutine()
|
|
{
|
|
isStopped = true;
|
|
yield return new WaitForSeconds(stopTime);
|
|
isStopped = false;
|
|
}
|
|
|
|
public void StopAndWait()
|
|
{
|
|
if (shouldStop)
|
|
{
|
|
StartCoroutine(StopCoroutine());
|
|
}
|
|
}
|
|
}
|