Ejemplo n.º 1
0
    void OnTriggerEnter(Collider collision)
    {
        Debug.Log("Collided with: " + collision.gameObject.tag);
        Debug.Log(collision.transform.position);

        if (collision.gameObject.tag == "Checkpoint")
        {
            int idx = linePositions.IndexOf(collision.gameObject.transform.position);
            if (idx == 1)
            {
                //save transform of this
                resetPosition = this.transform.position;
                resetRotation = this.transform.rotation;
                checkpoints_reached++;
                alert.text    = "Checkpoint " + checkpoints_reached + " Reached! ";
                alertDisplay  = 1.5f;
                alert.enabled = true;
                linePositions.RemoveAt(idx);

                if (linePositions.Count > 1)
                {
                    nextPath[1] = linePositions[1];
                    path.SetPositions(nextPath.ToArray());
                }
                else
                {
                    Destroy(path);
                    timerRun     = false;
                    raceFinished = true;
                }
            }
            else
            {
                // Collided with wrong checkpoint
                //alert.text = "Wrong Checkpoint!";
                //alertDisplay = 1.5f;
                //alert.enabled = true;
                Debug.Log("Wrong Checkpoint!!!");
            }
        }
        else
        {
            alert.text = "OOF!";

            timerRun           = false;
            countdownTimer     = true;
            mom.player_control = false;
            savetime           = timePassed;
            timePassed         = 0;

            //SET MOMENTUM TO ZERO


            mom.Decelerate_Momentum();
            mom.Turn(this.transform.rotation);

            alertDisplay = 3.0f;

            this.transform.rotation = resetRotation;
            this.transform.position = resetPosition;

            //Camera.main.ResetWorldToCameraMatrix();
        }
    }