Untitled
unknown
csharp
a year ago
988 B
23
Indexable
public class TrainScript : MonoBehaviour
{
private bool isDrivingFullSpeed = false;
private float trainSpeed = 0.5f;
private void FixedUpdate()
{
MovingTrain();
}
private void MovingTrain()
{
transform.position = transform.position + transform.forward * trainSpeed * Time.deltaTime;
if (!isDrivingFullSpeed)
{
trainSpeed += trainSpeed / 4 * Time.deltaTime;
if (trainSpeed >= 9.9)
{
isDrivingFullSpeed = true;
trainSpeed = 10f;
}
}
}
}
public class StickingBoxScript : MonoBehaviour
{
private void OnTriggerEnter(Collider other)
{
if(other.CompareTag("sticking"))
{
other.transform.parent = transform.parent.transform;
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("sticking"))
{
other.transform.parent = null;
}
}
}Editor is loading...
Leave a Comment