Esempio n. 1
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        RoadInfo check = other.GetComponent <RoadInfo>();

        if (check != null && !check.isEntrance())
        {
            setTurnRadius(check.getTurnRadiusDir());
            velocity = transform.InverseTransformDirection(carBody.velocity);
            this.transform.rotation = Quaternion.Euler(0, 0, check.getExitAngle());
            this.transform.position = check.getExitPos();
            velocity.x = Truncate(velocity.x, 2);
            velocity.y = 0;
        }
        if (check != null)
        {
            float speedLimit = check.getSpeedLimit();
            if (velocity.x != speedLimit)
            {
                float newAcc   = (speedLimit - velocity.x) > 0 ? 3 : -3;
                float timeStop = (speedLimit - velocity.x) / newAcc;
                if (varSACoroutine != null)
                {
                    StopCoroutine(varSACoroutine);
                }
                setAcceleration(newAcc);
                varSACoroutine = StopAcceleration(timeStop);
                StartCoroutine(varSACoroutine);
            }
        }
    }