Untitled

mail@pastecode.io avatar
unknown
csharp
24 days ago
988 B
7
Indexable
Never
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;
        }
    }
}
Leave a Comment