I'm new to unity, and I have two problems.

  1. I need to make an invisible area so that, when touched, the player warps back to the start.
  2. I need to make a cube that's when touched, it takes the player to a place that shows the player that they won.
  • 1
    \$\begingroup\$ Presumably you've tried doing this with OnTriggerEnter? How's your solution look so far? Where can we help beyond what you can already find in existing Unity tutorials? \$\endgroup\$ – DMGregory Jun 12 at 22:43
  • \$\begingroup\$ I don't even know how to apply code to anything. \$\endgroup\$ – R3Ked Jun 12 at 22:45
  • 2
    \$\begingroup\$ Then you should probably work your way through a few beginner's Unity tutorials to get a feel for the basics of the platform. Many of them will cover triggers and teleports, so you're likely to find your questions already answered in these guides. If you run into any trouble, please feel free to edit your question here or post a new one, with specific details of what you've tried so far and where you're stuck. \$\endgroup\$ – DMGregory Jun 12 at 22:47

These can both be accomplished using Unity's box colliders.

  1. First, Create your cube object. Expand the box collider options in the inspector and select 'Is Trigger.' Now object will no longer just collide with the object, they will pass through it and your code can then detect the collision.
  2. Next, add a script to your trigger cube. Click the 'add component' button at the foot of the inspector and click the 'new script' option and name it whatever you like.
  3. Add the OnTriggerEnter method to execute code when the object collides with the box collider. Then you can warp the player using this code where you replace x, y, and z with the actual coordinates you want the player to be moved to.
    public class <your script name> : MonoBehaviour
        // OnTriggerEnter is called when your rigid body enters the cube
        void OnTriggerEnter(Collider other) {
            // Transform (move) player's position to x, y, and z (Remember to set these values)
            Transform.position = new Vector3(x, y, z);

Now you just need to make two of these. One that takes the player to the end goal, and one that takes them back to the start.

One final note, make sure any game object you want to collide with these triggers have a Rigid Body or else it will not trigger the script


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.