• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
This question was closed Jan 26, 2016 at 12:06 PM by Daniel_Zabojca for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Daniel_Zabojca · Jan 19, 2016 at 01:00 PM · collision3dplayerteleportinteraction

Unty 3D C# Load other scene when bool = true, otherwise perform teleportation as commanded.

Hello everyone,

I got another question I wanted to ask.

I already got a teleport to target location when you exit one, so that is done. But what I want to achieve now is that when you have interacted with some object, that then The bool is set on true, and when you collide with the object this script is attached to you will be send to another scene, otherwise you will just be teleported to the beginning of this scene.

this is the script I assembled :

       using UnityEngine;
       using System.Collections;

          public class Telepiti : MonoBehaviour {
     /// <summary>
 /// Here I take the bool of if I am teleported, so that I can prevent spam      porting.
 /// Target = the point where I will be teleported to.
 /// </summary>
 public bool Interacted = false;
 public Interacted interact;
 public bool teleported = false;
 public Telepiti target;

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 
 }


 void OnTriggerEnter(Collider other)
 {
     ///<summary> 
     ///If I am teleported then It will be set to true and I will be teleported to point B
     ///Then It sets the teleport on false AND I will be able to teleport again!
     /// /summary>
     if (other.CompareTag("Player"))
     {
         if (!teleported)
         {
             ///<summary>
             //Teleports me to Location B AND turns me to a chosen degree with quaternion.Euler</summary>
             target.teleported = true; other.gameObject.transform.position = target.gameObject.transform.position;
             other.transform.rotation = Quaternion.Euler(0, 0, 0);
         }
     }
 }
 /// <summary>
 /// This gives me the possibility to teleport
 /// </summary>
 /// <param name="other"></param>
 void OnTriggerExit(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         teleported = false;
     }
 }
 }

Now I have walked into a wall, and I can not get past it. So what should I do to be able to Teleport to another scene IF the bool is set to true because I interacted with something? Should I make another void with onCollisionEnter? I am making an RPG horror game (something like Silent hill.). I want it to teleport you to another scene IF the bool = true, and if you did not interact with an object and collide with the Telepiti, then you will be teleported to Point B in the same scene.

I just do not know what I should do.

Thank you all again in advance for all your help, And have a nice day,

Daniel Nowak Janssen

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Socapex · Jan 19, 2016 at 06:57 PM

  if (other.CompareTag("Player"))
  {
      if (potato) {
          Application.Load("MyLevel2");
      }
      if (!teleported)
      {
          target.teleported = true; other.gameObject.transform.position = target.gameObject.transform.position;
          other.transform.rotation = Quaternion.Euler(0, 0, 0);
      }
  }

You could use else if, but it doesn't matter as the level will be destroyed and it wont continue checking further.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Daniel_Zabojca · Jan 21, 2016 at 10:39 AM 0
Share

I got this :

Script 1 :

  using UnityEngine;
  using System.Collections;

 public class Telepiti : $$anonymous$$onoBehaviour {

 public bool teleported = false;
 public Telepiti target;
 public bool Interacted;
  //  public Interacted interact;

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 
 }


 void OnTriggerEnter(Collider other)
 {

     if (other.CompareTag("Player"))
     {
         if (Interacted ==true) 
         {
             Application.LoadLevel("2");
         }
         if (!teleported)
         {
             target.teleported = true; other.gameObject.transform.position = target.gameObject.transform.position;
             other.transform.rotation = Quaternion.Euler(0, 0, 0);
         }
     }
 }
 
     void OnTriggerExit(Collider other)
  {
     if (other.CompareTag("Player"))
     {
         teleported = false;
     }
  }


 }


Script 2 :

     public class NextLevelInteraction : $$anonymous$$onoBehaviour {
      GameObject mainCamera;
     public float interactDistance = 1f;
      public Telepiti Teleportation;

    void Start () {
     mainCamera = GameObject.FindWithTag("$$anonymous$$ainCamera");
     GameObject G = GameObject.FindGameObjectWithTag ("Special");
     Teleportation = G.GetComponent<Telepiti>();
     Teleportation.Interacted = false;
 }
 
 // Update is called once per frame
 void Update () {
     
 }
 void pickup()
 {
     if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.E))
     {
         int x = Screen.width / 2;
         int y = Screen.height / 2;
        
         Ray ray = mainCamera.GetComponent<Camera>().ScreenPointToRay(new Vector3(x, y));
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, interactDistance))
             Debug.Log("Touching your special things.... huehuehue");
         {
             SpecialPick p = hit.collider.GetComponent<SpecialPick>();
             Teleportation.Interacted = true;
             
             if (p != null)
             {
                 
                 Debug.Log("magic!");
             }
         }
     }
 }

}

And somehow he does NOT want to change interacted to true...

What Have I done wrong?

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

45 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Death from collision 1 Answer

Mining from a chunk? - 3d Game Cavern Generation + Player integration 0 Answers

Collision Detection Modes not working for what I need? 0 Answers

Unity 3D #C Nightvision does not want to switch on or off. 0 Answers

Unity3d OnCollisionEnter not firing 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges