Example #1
0
 void OnTriggerEnter(Collider c)
 {
     if (c.name == "Player")
     {
         currentCheckpoint = this;
     }
 }
Example #2
0
    GameObject GetNearestActiveCheckpoint()
    {
        GameObject[] checkpoints =
            GameObject.FindGameObjectsWithTag("Checkpint");
        GameObject nearestCheckpoint = null;
        float      shortestDistance  = Mathf.Infinity;

        foreach (GameObject checkpoint in checkpoints)
        {
            Vector3 checkpointPosition = checkpoint.transform.position;
            float   distance           =
                (checkpointPosition - transform.position).sqrMagnitude;


            CheckpointTrigger trigger =
                checkpoint.GetComponent <CheckpointTrigger>();

            if (distance < shortestDistance && trigger.isTriggered == true)
            {
                nearestCheckpoint = checkpoint;
                shortestDistance  = distance;
            }
        }
        return(nearestCheckpoint);
    }
Example #3
0
        public void InitialState_IsNotActive()
        {
            // act
            var ct = new CheckpointTrigger(2, TimeSpan.FromSeconds(5));

            // assert
            ct.IsEnabled.Should().BeFalse();
        }
        public void WhenNewInstanceThenIsNotActive()
        {
            // act
            var ct = new CheckpointTrigger(2, TimeSpan.FromSeconds(5));

            // assert
            ct.IsEnabled.Should().BeFalse();
        }
Example #5
0
        public void AfterDurationReached_ShouldBecomeActive()
        {
            var ct = new CheckpointTrigger(2, TimeSpan.FromSeconds(2));

            // act
            Thread.Sleep(2500);
            var isActive = ct.Increment();

            // assert
            ct.IsEnabled.Should().BeTrue();
            isActive.Should().BeTrue();
        }
Example #6
0
        public void AfterReset_ShouldBecomeNotActive()
        {
            var ct = new CheckpointTrigger(2, TimeSpan.FromHours(1));

            ct.Increment();
            ct.Increment();

            // act
            ct.Reset();

            // assert
            ct.IsEnabled.Should().BeFalse();
        }
Example #7
0
        public void AfterCountReached_ShouldBecomeActive()
        {
            var ct = new CheckpointTrigger(2, TimeSpan.FromHours(1));

            // act
            var i1 = ct.Increment();
            var i2 = ct.Increment();

            // assert
            ct.IsEnabled.Should().BeTrue();
            i1.Should().BeFalse();
            i2.Should().BeTrue();
        }
 public void ActivateCheckpoint(CheckpointTrigger checkpoint)
 {
     RespawnLocation = checkpoint.RespawnLocation.transform.position;
 }
Example #9
0
    private void DoRespawn()
    {
        SetState(PlayerState.Idle);

        if (gameHUD)
        {
            gameHUD.DoRespawn();
        }

        gravityAlterations.Clear();
        gravityContacts.Clear();
        gravity     = Physics.gravity;
        gravityLerp = gravityDir;

        Time.timeScale = 1.0f;

        GetComponent <Rigidbody>().velocity = Vector3.zero;

        // We have a checkpoint?
        foreach (GameObject obj in GameObject.FindGameObjectsWithTag("Checkpoint"))
        {
            CheckpointTrigger checkpoint = obj.GetComponent <CheckpointTrigger>();
            if (checkpoint && checkpoint.activated)
            {
                // Restore every collectable active state to the states stored in the checkpoint.
                foreach (GameObject collectable in Collectable.AllCollectables)
                {
                    if (collectable)
                    {
                        collectable.SetActive(true);
                    }
                }
                foreach (GameObject collectable in checkpoint.collectables)
                {
                    if (collectable)
                    {
                        collectable.SetActive(false);
                    }
                }

                // Go to the checkpoint position and rotation.
                transform.position = obj.transform.position;
                transform.rotation = obj.transform.rotation;

                if (playerCamera)
                {
                    playerCamera.Reset();
                }

                if (respawnSound)
                {
                    GetComponent <AudioSource>().PlayOneShot(respawnSound);
                }

                return;
            }
        }

        // Otherwise just start the entire level over again, including the timer.
        GameObject respawnobj = GameObject.FindGameObjectWithTag("Respawn");

        if (respawnobj)
        {
            transform.position = respawnobj.transform.position;
            transform.rotation = respawnobj.transform.rotation;
        }
        else
        {
            transform.position = Vector3.zero;
            transform.rotation = Quaternion.identity;
        }

        levelStartTime = 0.0f;

        // Restore all the collectables.
        if (Collectable.AllCollectables != null)
        {
            foreach (GameObject collectable in Collectable.AllCollectables)
            {
                if (collectable)
                {
                    collectable.SetActive(true);
                }
            }
        }
    }