Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 Apr 21, 2016 at 06:33 PM by VanceOnTheInternet for the following reason:

Problem solved by OP

avatar image
0
Question by VanceOnTheInternet · Apr 21, 2016 at 04:04 PM · teleportteleportingjavascript-specific

Half working Teleport Script

Hello community,

I am part of a group making a historical visualization. I am trying to adapt and update a pause/teleport script that was used in a previous project that ran in Unity 3.5. The script is supposed to allow the user to hit escape, then click on a GUI button and be teleported to the corresponding location. This is my first attempt at scripting in Unity and I have only a cursory knowledge of Javascript, so I kind of fumbling my way through it.

I have got the pause and gui functions to work. Unfortunately, when you click on button to teleport, it is like only the camera is teleported, and as soon as the you move, the you back at the starting point again. I pasted my code at them bottom. I have left in what I commented out from the original script, as maybe someone with more knowledge than me can see how it was done previously. I have a feeling it has something to do with enabling and disabling the camera.

Any help is greatly appreciated.

 #pragma strict
 
 public var locations: Transform[];
 private var paused : boolean;
 private var guiSkin : GUISkin;
 //private var fpcMouseLook : MouseLook;
 //private var camMouseLook : MouseLook;
 //private var crosshairScript : CrosshairScript;
 private var fpc : GameObject;
 
 // private var minimap : MinimapScript;
 function Start() 
 {
     Cursor.lockState = CursorLockMode.Locked;
     Cursor.visible = false;
 }
 
 function Awake() 
 {
     fpc = GameObject.Find("FirstPersonCharacter");
     //fpcMouseLook = fpc.GetComponent(MouseLook);
     //camMouseLook = GameObject.Find("MainCamera").GetComponent(MouseLook);
     //crosshairScript = GameObject.Find("Crosshair").GetComponent(CrosshairScript);
 }
 
 function Update () 
 {
     if(Input.GetKeyDown("escape")) 
     {
         paused = !paused;
     }
     if(paused) 
     {
         Time.timeScale = 0;
         Cursor.lockState = CursorLockMode.None;
         Cursor.visible = true;
         AudioListener.pause = true;
         //enableCamera(false);
         //crosshairScript.hide();
     }
     else 
     {
         Time.timeScale = 1;
         Cursor.lockState = CursorLockMode.Locked;
         Cursor.visible = false;
         AudioListener.pause = false;
         //enableCamera(true);
         //crosshairScript.show();
     }
 }
 
 function OnGUI () 
 {
     GUI.skin = guiSkin;
     if(paused) 
     {
         GUI.Box(Rect(-5, -5, Screen.width+10, Screen.height+10), "");
         GUI.Box(Rect(Screen.width/2 - 265, Screen.height/2, 530, 130), "Jump to a location:");
         
         // Resume button
         if (GUI.Button (Rect (Screen.width/2 - 60, Screen.height/2 - 80, 120, 40), "Resume")) 
         {
             paused = false;
         }
                                              
 
         // Go to Apartment 12-8-A
         if (GUI.Button (Rect (Screen.width/2 - 190, Screen.height/2 + 30, 120, 40), "Apartment 12-8-A")) 
         {
             // setPosition(289, 2, 225, 318);
             fpc.transform.position = locations[0].position;
             paused = false;
         }
 
         // Go to Mess Hall
         if (GUI.Button (Rect (Screen.width/2 - 60, Screen.height/2 + 30, 120, 40), "Mess Hall")) 
         {
             // setPosition(287, 2, 227, 270);
             fpc.transform.position = locations[1].position;
             paused = false;
         }
 
         // Go to Start Location
         if (GUI.Button (Rect (Screen.width/2 + 70, Screen.height/2 + 30, 120, 40), "Start Location")) 
         {
             // setPosition(245, 2, 260, 245);
             fpc.transform.position = locations[2].position;
             paused = false;
         }
 
     }
 }
 
 function showPause() 
 {
     paused = true;
 }
 
 function hidePause() 
 {
     paused = false;
 }
 
 function isPaused()
 {
     return paused;
 }
 
 //function enableCamera(enable : boolean) 
 //{
     //fpcMouseLook.enabled = enable;
     //camMouseLook.enabled = enable;
 //}
 
 //function setPosition(x : float, y : float, z : float, r : float)
 //{
     // minimap.setPosition(x, z);
     // fpc.transform.position.x = x;
     // fpc.transform.position.y = y;
     // fpc.transform.position.z = z;
     // fpcMouseLook.SetRotationY = r;
     // fpcMouseLook.rotationY = r;
 //}
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
0

Answer by VanceOnTheInternet · Apr 21, 2016 at 06:31 PM

And... I fixed it. My problem was the script was placed on the FirstPersonCharacter, but needed to be placed on the parent FPScontroller. So it works as intended!

Comment
Add comment · 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

Follow this Question

Answers Answers and Comments

55 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to move a character along the Y axis x amount of units using the G key? 1 Answer

need help teleporting an object 0 Answers

How to teleport an object to 1 of 8 possible locations on collision? 1 Answer

How to teleport player in unity using X, Y, Z axis,How to teleport a player using X,Y,Z. 0 Answers

I am instantiating prefabs and listing them on a scroll list. I am trying to teleport the player to instantiated prefab position when i click on scroll list listing? 0 Answers


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