Search Unity

Skyrim Style Doors

Discussion in 'Scripting' started by Studio_Akiba, Dec 22, 2014.

  1. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    I am trying to create a skyrim styled door script for our upcoming game, and I really need help with this script.

    It is my first time using DontDestroyOnLoad and I am a 3D artist and modeller by trade, so excuse me if my scripting is complete c***.

    Here is the code:

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var PlayerCharacter : Transform;
    4. private var drawGUI = false;
    5. var NewScene : String = "";
    6.  
    7. function Update ()
    8. {
    9. if (drawGUI == true && Input.GetKeyDown(KeyCode.F))
    10. {
    11.      LoadNewScene();
    12. }
    13. }
    14.  
    15. function OnTriggerEnter (theCollider : Collider)
    16. {
    17.     if (theCollider.tag == "Player")
    18.     {
    19.         drawGUI = true;
    20.     }
    21. }
    22.  
    23. function LoadNewScene ()
    24. {
    25.     DontDestroyOnLoad(PlayerCharacter);
    26.     Application.LoadLevel(NewScene);
    27. }
     
  2. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    I have managed to get the loading working, the only problem I now have is that the GUI element (the text) will not appear on collision.
    The code is posted below.

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var PlayerCharacter : Transform;
    4. private var drawGUI = false;
    5. var NewScene : String = "";
    6.  
    7. function Update ()
    8. {
    9. if (drawGUI == true && Input.GetKeyDown(KeyCode.F))
    10. {
    11.      LoadNewScene();
    12. }
    13. }
    14.  
    15. function OnTriggerEnter (theCollider : Collider)
    16. {
    17.     if (theCollider.tag == "Player")
    18.     {
    19.         drawGUI = true;
    20.     }
    21. }
    22.  
    23. function LoadNewScene ()
    24. {
    25.     DontDestroyOnLoad(PlayerCharacter);
    26.     Application.LoadLevel(NewScene);
    27. }
    28.  
    29. function onGUI()
    30. {
    31.     if (drawGUI == true)
    32.     {
    33.         GUI.Box (Rect (Screen.width*0.5-51, 200, 102, 22), "Press F to open");
    34.     }
    35. }
     
  3. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    onGUI should be OnGUI... the functions are case sensitive, I actually have a codechecking asset that checks for all those sort of errors....

    not quite ready for release to the store yet though... hopefully it will be out at the beginning of the year.... ( mainly just need to write the documentation and fulfill all the requirements for submission to the asset store
     
  4. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    Code (JavaScript):
    1. function OnGui(); // <- not onGui();
    And in your other thread, you said this:
    I'm not quite sure what you mean, do you just mean setting the players position to the position of the transform of another object?

    Code (JavaScript):
    1. player.transform.position = otherGameObject.transform.position;
     
  5. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    Yes, because I am crossing between scenes, I will need to set the player back to a position on the inside of a door, which will be represented by an object called SpawnPoint, because I will be doing this for hundreds of doors, I will need the ability to call this via name, and not by dragging the object into a script.
     
  6. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    Code (JavaScript):
    1. //Assuming the door game object has a child game object named "SpawnPoint"
    2.  
    3. var spawnPoint : Transform = doorGameObject.transform.Find("SpawnPoint");
    4.  
    5. player.transform.position = spawnPoint.position;
    Remember, if you're in the MonoDevelop script environment you can press + ' when text is selected to automatically look it up on the unity scripting API. (That's mac not sure what the keyboard shortcut is for windows. Probably CTRL + ')

    People in the forum are not going to mind helping you out with simple things like this, but it will definitely save you a lot of frustration and waiting if you check out the documentation first!
     
  7. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    I have noticed that I cannot center the GUI text, anyone have any ideas on how to do that?

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var PlayerCharacter : Transform;
    4. private var drawGUI = false;
    5. var NewScene : String = "";
    6. var toText : String = "";
    7.  
    8. function Update ()
    9. {
    10. if (drawGUI == true && Input.GetKeyDown(KeyCode.F))
    11. {
    12.      LoadNewScene();
    13. }
    14. }
    15.  
    16. function OnTriggerEnter (theCollider : Collider)
    17. {
    18.     if (theCollider.tag == "Player")
    19.     {
    20.         drawGUI = true;
    21.     }
    22. }
    23.  
    24. function LoadNewScene ()
    25. {
    26.     DontDestroyOnLoad(PlayerCharacter);
    27.     Application.LoadLevel(NewScene);
    28. }
    29.  
    30. function OnGUI()
    31. {
    32.     if (drawGUI == true)
    33.     {
    34.         GUI.Label (Rect (Screen.width*0.5-51, 200, 120, 22), "Press F to open to");
    35.         GUI.Label (Rect (Screen.width*0.5-51, 220, 150, 22), toText);
    36.     }
    37. }
     
  8. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    OK, I got it working...finally, the only thing I need to do now is work out how to map the transform of an object that can be added as a string onto the character and teleport them there on the loading of the new level. any ideas?

    The code is posted below.

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var PlayerCharacter : Transform;
    4. private var drawGUI = false;
    5. var NewScene : String = "";
    6. var toText : String = "";
    7.  
    8. function Update ()
    9. {
    10. if (drawGUI == true && Input.GetKeyDown(KeyCode.F))
    11. {
    12.      LoadNewScene();
    13. }
    14. }
    15.  
    16. function OnTriggerEnter (theCollider : Collider)
    17. {
    18.     if (theCollider.tag == "Player")
    19.     {
    20.         drawGUI = true;
    21.     }
    22. }
    23.  
    24. function LoadNewScene ()
    25. {
    26.     DontDestroyOnLoad(PlayerCharacter);
    27.     Application.LoadLevel(NewScene);
    28. }
    29.  
    30. function OnGUI()
    31. {
    32.     if (drawGUI == true)
    33.     {
    34.         //GUI.Label (Rect (Screen.width*0.5-0, 200, 120, 22), "Press F to open to");
    35.         //GUI.Label (Rect (Screen.width*0.5-35, 220, 150, 22), toText);
    36.        
    37.        
    38.     GUI.BeginGroup (Rect (Screen.width / 2 - 75, Screen.height / 2 - 50, 150, 48));
    39.  
    40.     GUI.Box (Rect (0,0,150,24), "Press F to open to");
    41.     GUI.Box (Rect (0,22,150,24), toText);
    42.    
    43.     GUI.EndGroup ();
    44.     }
    45. }
    46.  
    47. function OnTriggerExit (theCollider : Collider)
    48. {
    49.     if (theCollider.tag == "Player")
    50.     {
    51.         drawGUI = false;
    52.     }
    53. }
     
  9. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    I'd separate all the functionality into several scripts. And there is probably a problem, as you have obviously put the player into the main world: As soon as you load the main scene again, there will be another player character. You should always ensure that objects which only exist once in your game will not be created several times when using DontDestroyOnLoad(....).

    Anyway, you could now make a script that is attached to the gameObject you want to spawn at. Find the player when the level is loaded (OnLevelWasLoaded) or in the scripts Awake or Start method, then assign the transform data to the player objects transform.

    I'll try to post my version soon as i got time now, but it will be in C# if you don't mind.
    *Edit gotta fix one more bug tomorrow, if you still need it then, I'll post it.
     
    Last edited: Dec 23, 2014
  10. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    I have managed to get a little further, I am now trying to add the spawn object into the same script, but as it is in another scene (and will be in many) I cannot drag it over as a GameObject variable.
    I am currently trying to locate an object via its name stores in a string and grab the transform data from that.

    I am now getting the error below with the code:
    Assets/Scripts/Events/DoorScript.js(32,38): BCE0019: 'position' is not a member of 'Object'.

    Code is below:

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var PlayerCharacter : Transform;
    4. var SpawnPoint : String = "";
    5. private var drawGUI = false;
    6. private var Spawner;
    7. var NewScene : String = "";
    8. var toText : String = "";
    9.  
    10. function Update ()
    11. {
    12. if (drawGUI == true && Input.GetKeyDown(KeyCode.F))
    13. {
    14.      LoadNewScene();
    15. }
    16. }
    17.  
    18. function OnTriggerEnter (theCollider : Collider)
    19. {
    20.     if (theCollider.tag == "Player")
    21.     {
    22.         drawGUI = true;
    23.     }
    24. }
    25.  
    26. function LoadNewScene ()
    27. {
    28.     DontDestroyOnLoad(PlayerCharacter);
    29.     Application.LoadLevel(NewScene);
    30.    
    31.     Spawner = GameObject.Find(SpawnPoint);
    32.     transform.position = Spawner.position;
    33. }
    34.  
    35. function OnGUI()
    36. {
    37.     if (drawGUI == true)
    38.     {
    39.         //GUI.Label (Rect (Screen.width*0.5-0, 200, 120, 22), "Press F to open to");
    40.         //GUI.Label (Rect (Screen.width*0.5-35, 220, 150, 22), toText);
    41.        
    42.        
    43.     GUI.BeginGroup (Rect (Screen.width / 2 - 75, Screen.height / 2 - 50, 150, 48));
    44.  
    45.     GUI.Box (Rect (0,0,150,24), "Press F to open to");
    46.     GUI.Box (Rect (0,22,150,24), toText);
    47.    
    48.     GUI.EndGroup ();
    49.     }
    50. }
    51.  
    52. function OnTriggerExit (theCollider : Collider)
    53. {
    54.     if (theCollider.tag == "Player")
    55.     {
    56.         drawGUI = false;
    57.     }
    58. }
     
  11. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    Fixed the issue with positions, the GUI text is not transparent and still centered, but lowered slightly.

    All I need now is to be able to copy the transform from an object and paste it into the players after the new scene loads.

    I have thought about the duplication glitch, and not sure how to fix it yet, but here's the latest code update:


    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var PlayerCharacter : Transform;
    4. var SpawnPoint : String = "";
    5. private var drawGUI = false;
    6. private var Spawner;
    7. var NewScene : String = "";
    8. var toText : String = "";
    9.  
    10. function Update ()
    11. {
    12. if (drawGUI == true && Input.GetKeyDown(KeyCode.F))
    13. {
    14.      LoadNewScene();
    15. }
    16. }
    17.  
    18. function OnTriggerEnter (theCollider : Collider)
    19. {
    20.     if (theCollider.tag == "Player")
    21.     {
    22.         drawGUI = true;
    23.     }
    24. }
    25.  
    26. function LoadNewScene ()
    27. {
    28.     DontDestroyOnLoad(PlayerCharacter);
    29.     Application.LoadLevel(NewScene);
    30.    
    31.     Spawner = GameObject.Find(SpawnPoint).transform.position;
    32.     //Vector3 position = Spawner.transform;
    33.    
    34. }
    35.  
    36. function OnGUI()
    37. {
    38.     if (drawGUI == true)
    39.     {
    40.         //GUI.Label (Rect (Screen.width*0.5-0, 200, 120, 22), "Press F to open to");
    41.         //GUI.Label (Rect (Screen.width*0.5-35, 220, 150, 22), toText);
    42.        
    43.     //GUI.color = new Color(1,1,1,1.0f);
    44.     GUI.skin.box.fontSize=15;
    45.     GUI.backgroundColor = Color(0, 0, 0, 0);
    46.     GUI.BeginGroup (Rect (Screen.width / 2 - 75, Screen.height / 2 - 0, 150, 50));
    47.  
    48.     GUI.Box (Rect (0,0,150,25), "Press F to open to");
    49.     GUI.Box (Rect (0,22,150,25), toText);
    50.    
    51.     GUI.EndGroup ();
    52.     }
    53. }
    54.  
    55. function OnTriggerExit (theCollider : Collider)
    56. {
    57.     if (theCollider.tag == "Player")
    58.     {
    59.         drawGUI = false;
    60.     }
    61. }
     
  12. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    I can only repeat myself here, you should make a script for the interior scenes that will move your player to the desired location. You'd find the player and your spawn point (if that's not the object the script is already attached to) and simply assign the appropiate data to the player object's transform.
    Your current script will most likely throw an error, as you try to load the new scene and immediately try to find the spawn point. That line can still be executed but will probably happen in the old scene.

    As promised, i tried that myself and it works. It's not perfect, the scripts I prepared will do the trick for singleplayer games.

    Here's a quick example, which consists of three scripts:
    - for the sake of brevity i left out null-checks
    - suggestions and critism, both are welcome


    Code (CSharp):
    1.  
    2. // just placed it here in order to reduce number of scripts
    3. public enum Scenes { mainLevel, interior_1, interior_2 }
    4.  
    5. public class SpawnController : MonoBehaviour
    6. {
    7.     // following two statics could be part of the player script
    8.     // that's a matter of design
    9.  
    10.     // save the last world position here at which you
    11.     // entered the instance
    12.     public static Vector3 mainWorldPosition = new Vector3(0, 1, 0);
    13.     // save the rotation here which should be applied when
    14.     // respawning in the main world again
    15.     public static Quaternion mainWorldRotation;
    16.  
    17.     void Start()
    18.     {
    19.         // no matter which scene, try to find the player
    20.         GameObject playerGO = GameObject.FindGameObjectWithTag("Player");
    21.  
    22.         // is it the main level (currently assumes index is 0)
    23.         if (Application.loadedLevel == (int)Scenes.mainLevel)
    24.         {
    25.             // restore the data we had saved
    26.             RestoreMainWorldTransformData(playerGO.transform);
    27.         }
    28.         else
    29.         {
    30.             // in any other scene: assign the data from the
    31.             // script's (object's) transform to the player's transform
    32.             SetPlayerPosition(playerGO.transform);
    33.         }
    34.     }
    35.  
    36.     // Helper methods - they could also belong to the player class
    37.     // matter of design
    38.  
    39.     // Used to restore the main scene position
    40.     private void RestoreMainWorldTransformData(Transform t)
    41.     {
    42.         t.position = mainWorldPosition;
    43.         t.rotation = mainWorldRotation;
    44.     }
    45.  
    46.     // used to move the player to the position of the spawn object
    47.     // which holds this script
    48.     private void SetPlayerPosition(Transform t)
    49.     {
    50.         t.position = transform.position;
    51.         t.rotation = transform.rotation;
    52.     }
    53.     // static method which is used to store the last main scene data,
    54.     // so we 'remember' where we have to spawn when leaving the instance
    55.     public static void SetMainWorldSpawnData(Transform t)
    56.     {
    57.         mainWorldPosition = t.position;
    58.         mainWorldRotation = t.rotation;
    59.     }
    60. }
    61.  
    62.  

    Code (CSharp):
    1. public class EnterOrExit : MonoBehaviour
    2. {
    3.     // actually a bad solution to use a boolean and Update in this script...
    4.     // I'd probably prefer using delegates in combination with one single Update function in
    5.     // another 'manager' script - hint for improvement
    6.  
    7.     // stores whether the player entered the trigger or not
    8.     private bool playerInTrigger = false;
    9.     // enumeration, based on int by default (in order to simply the code i simply used to cast the
    10.     // enum with (int) in the scripts since we know the underlying integral type here
    11.     public Scenes levelToLoad;
    12.  
    13.     void Update()
    14.     {
    15.         // check whether the player entered the trigger and if the key F is pressed
    16.         if (playerInTrigger && Input.GetKeyDown(KeyCode.F))
    17.         {
    18.             // is it the main level?
    19.             if (Application.loadedLevel == (int)Scenes.mainLevel)
    20.             {
    21.                 // if so, get data from this transform and store it for respawn
    22.                 SpawnController.SetMainWorldSpawnData(transform);
    23.             }
    24.             // either way, load the level specified in the inspector
    25.             Application.LoadLevel((int)levelToLoad);
    26.         }
    27.     }
    28.     // simply check if it's the player that entered this trigger
    29.     void OnTriggerEnter(Collider trigger)
    30.     {
    31.         if (trigger.tag == "Player")
    32.         {
    33.             playerInTrigger = true;
    34.         }
    35.     }
    36.     // simply check if it's the player that exited this trigger
    37.     void OnTriggerExit(Collider trigger)
    38.     {
    39.         if (trigger.tag == "Player")
    40.         {
    41.             playerInTrigger = false;
    42.         }
    43.     }
    44. }

    Code (CSharp):
    1.  
    2. // this will ensure we'll have a CharacterController, if you attach this script and there is none
    3. // it will automatically add one
    4. [RequireComponent(typeof(CharacterController))]
    5. public class Player : MonoBehaviour
    6. {
    7.     // holds the reference to the player, we only want to have one no matter how often we reload       // scenes where the player would be loaded again...
    8.     private static Player player;
    9.     // just so we can move it with the 'move'-method as we're not using
    10.     private CharacterController charController;
    11.  
    12.     void Awake()
    13.     {
    14.         // check if the player already exists, if so, destroy this object
    15.         if (player)
    16.         {
    17.             Destroy(gameObject);
    18.             // just to make sure nothing else is executed in here
    19.             return;
    20.         }
    21.         // otherwise set up all the references
    22.         charController = GetComponent<CharacterController>();
    23.         player = this;
    24.         // let the object 'survive' scene changes
    25.         DontDestroyOnLoad(gameObject);
    26.     }
    27.  
    28.     // Basic movement for testing
    29.     void Update()
    30.     {
    31.         Vector3 moveVector = Vector3.zero;
    32.         if (Input.GetKey(KeyCode.W))
    33.         {
    34.             moveVector.z += 1;
    35.         }
    36.         if (Input.GetKey(KeyCode.S))
    37.         {
    38.             moveVector.z -= 1;
    39.         }
    40.         charController.Move(transform.TransformDirection(moveVector) * Time.deltaTime);
    41.     }
    42. }

    1) Create a main scene and some other secondary scenes.
    2) Add the main scene to the build settings, afterwards add the other scenes. The current script assumes the main scene will have the index 0, of course this can be adjusted.

    Main scene:
    3) Create basic scene setup, e.g. a plane (ground), a cube (door), another cube (door trigger). Maybe add a light as well.
    4) The door trigger should be a child of the door. Note that the script also uses the triggers rotation (actually the orientation) in order to make the player face away from the door when being spawned. So you could make sure the trigger's positive local z-axis faces away from the door.
    Also, enable 'isTrigger' on the collider of the door trigger object.
    5) Attach the script 'EnterOrExit.cs' to the trigger. You can now save the door as a prefab and reuse it by dragging it whereever you want to. Place another door and turn it by 180 degrees so you can test the whole setup with two secondary scenes.

    6) Note: the script on the trigger provides a public enumeration value which corresponds to the level index' you want to load by 'using' the door. In the main scene, you'd logically want to specify a different value to each door.
    7) Create an empty object in the main scene which holds the script: 'SpawnController.cs'. Details about it below.
    8) Create a capsule, remove its collider and attach 'Player.cs' to it. CharacterController will be added automatically. Don't forget to tag it with 'Player'. Note, that I only made it move in z-direction (forwards, backwards ) to keep it simple. Make sure the player is between both doors so that you can enter both.

    All kinds of secondary level:
    8) Create a similar setup, e.g. ground plane and put in the door prefab you had saved before.
    9) Now you need the script 'SpawnController.cs' again, this time, attach it to the trigger (or to an object that represents your spawn point).
    10) Rename the new door's root object and make a prefab out of it, so that you have one for the main world (without the SpawnController.cs script) and one for the
    secondary scenes.

    Again a short overview about the scripts:
    SpawnController script:

    The SpawnController.cs script should only exist once in the main scene. When started, it tests whether the last loaded level was the main scene and if so it will set the players position to the last known data in the static variables. This happens every time the main scene is laoded, you need to adjust the initial values to fit your savegame data later on, as this will always have default values when the program starts.

    When not used in the main scene, it sets the players position/rotation to the transforms position/rotation which holds the script. Thus, you can add this script to either the door trigger in order to spawn at the door as you would usually expect, but also to any other object which should represents the spawn location.

    EnterOrExit script:
    When the player enters the trigger that this script is attached to, the trigger method will be called and sets the boolean to true, thus you can now confirm to load the 'scene behind that door' by pressing the F key. This is just quick point in the right direction, it can be achieved in different ways and that's rather an ugly one. :p
    As soon as you confirmed to enter/exit the scene, the position and orientation of the trigger object will be stored in order to get back to exactly where you entered in the main scene.
    And that's actually, at least i assume, what you wanted.

    Player script:
    Just represents the player and does ensure there's only one player (kind of singleton).
    However, it can be improved a lot and it's just the quick way I'd try to achieve the effect. But one thing i'd make for sure is the thing with the delegates i mentioned in the second script.
     
    Last edited: Dec 23, 2014
  13. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    @Suddoha
    Looked through this but I am not sure if any of it will help much, I am a 3D artist mostly, I have just been tasked to do this.
    I understand quite a bit of code myself, but I am not sure if I am experienced enough to be able to do this easily.

    I did wish this was easier though, how would I get rid of duplicates between scenes, is there any quick fix for that either?
     
  14. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    You could force any further duplicate to destroy itself in Awake. In order to do this, you could store your first created player (reference to the script's/class' instance in this case) in a static variable and test in Awake whether it is still unassigned or not. If unassigned, no player has been created and you can continue your initialization (don't forget to assign the current instance to that variable then). If there is already a player, don't initialize anything, simply destroy the gameobject and return from the method.

    If you understand C# a little bit, you can have a look at the Player.cs i posted earlier. The Awake contains quite the minimum in order to achieve that.

    Also, if you take out all the comments, it's not that much code.
     
  15. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    I am not getting this error:
    Assets/Scripts/Events/DoorScript.js(33,54): BCE0019: 'position' is not a member of 'Object'.
    It has something to do with not being able to use .position on something, it is talking about Spawner but I have set the script to find the objects position before that, so it should not have any problems doing that.

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var PlayerCharacter : Transform;
    4. var SpawnPoint : String = "";
    5. private var drawGUI = false;
    6. private var Spawner;
    7. var NewScene : String = "";
    8. var toText : String = "";
    9.  
    10. function Update ()
    11. {
    12. if (drawGUI == true && Input.GetKeyDown(KeyCode.F))
    13. {
    14.      LoadNewScene();
    15. }
    16. }
    17.  
    18. function OnTriggerEnter (theCollider : Collider)
    19. {
    20.     if (theCollider.tag == "Player")
    21.     {
    22.         drawGUI = true;
    23.     }
    24. }
    25.  
    26. function LoadNewScene ()
    27. {
    28.     DontDestroyOnLoad(PlayerCharacter);
    29.     Application.LoadLevel(NewScene);
    30.    
    31.     Spawner = GameObject.Find(SpawnPoint).transform.position;
    32.     //Vector3 position = Spawner.transform;
    33.     PlayerCharacter.transform.position = Spawner.position;
    34.    
    35. }
    36.  
    37. function OnGUI()
    38. {
    39.     if (drawGUI == true)
    40.     {
    41.         //GUI.Label (Rect (Screen.width*0.5-0, 200, 120, 22), "Press F to open to");
    42.         //GUI.Label (Rect (Screen.width*0.5-35, 220, 150, 22), toText);
    43.        
    44.     //GUI.color = new Color(1,1,1,1.0f);
    45.     GUI.skin.box.fontSize=15;
    46.     GUI.backgroundColor = Color(0, 0, 0, 0);
    47.     GUI.BeginGroup (Rect (Screen.width / 2 - 75, Screen.height / 2 - 0, 150, 50));
    48.  
    49.     GUI.Box (Rect (0,0,150,25), "Press F to open to");
    50.     GUI.Box (Rect (0,22,150,25), toText);
    51.    
    52.     GUI.EndGroup ();
    53.     }
    54. }
    55.  
    56. function OnTriggerExit (theCollider : Collider)
    57. {
    58.     if (theCollider.tag == "Player")
    59.     {
    60.         drawGUI = false;
    61.     }
    62. }
     
  16. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    Code (JavaScript):
    1. Spawner = GameObject.Find(SpawnPoint).transform.position;
    2.     PlayerCharacter.transform.position = Spawner.position;
    You did not specify the type of 'Spawner' with the declaration.
    Thus you won't be able to access any member such as position, it's unclear which type 'Spawner' is going to be (for you it is, you want it to be Vector3, but even then, a Vector3 would not have a member called 'position'.)

    That is, remove '.position' at Spawner in the second line i quoted. Additionally, you should also declare Spawner as a Vector3 if you know the type ahead.
     
  17. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    For some reason I am unable to enter it even manually, it doesn't seem to want to reposition the character at all.

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var PlayerCharacter : Transform;
    4. var SpawnPoint : String = "";
    5. private var drawGUI = false;
    6. var Spawner : Vector3;
    7. var NewScene : String = "";
    8. var toText : String = "";
    9.  
    10. function Update ()
    11. {
    12. if (drawGUI == true && Input.GetKeyDown(KeyCode.F))
    13. {
    14.      LoadNewScene();
    15. }
    16. }
    17.  
    18. function OnTriggerEnter (theCollider : Collider)
    19. {
    20.     if (theCollider.tag == "Player")
    21.     {
    22.         drawGUI = true;
    23.     }
    24. }
    25.  
    26. function LoadNewScene ()
    27. {
    28.     DontDestroyOnLoad(PlayerCharacter);
    29.     Application.LoadLevel(NewScene);
    30.     yield WaitForSeconds (0.2);
    31.     Spawner = GameObject.Find(SpawnPoint).transform.position;
    32.     //Vector3 position = Spawner.transform;
    33.     PlayerCharacter.transform.Translate(Spawner);
    34.    
    35. }
    36.  
    37. function OnGUI()
    38. {
    39.     if (drawGUI == true)
    40.     {
    41.         //GUI.Label (Rect (Screen.width*0.5-0, 200, 120, 22), "Press F to open to");
    42.         //GUI.Label (Rect (Screen.width*0.5-35, 220, 150, 22), toText);
    43.        
    44.     //GUI.color = new Color(1,1,1,1.0f);
    45.     GUI.skin.box.fontSize=15;
    46.     GUI.backgroundColor = Color(0, 0, 0, 0);
    47.     GUI.BeginGroup (Rect (Screen.width / 2 - 75, Screen.height / 2 - 0, 150, 50));
    48.  
    49.     GUI.Box (Rect (0,0,150,25), "Press F to open to");
    50.     GUI.Box (Rect (0,22,150,25), toText);
    51.    
    52.     GUI.EndGroup ();
    53.     }
    54. }
    55.  
    56. function OnTriggerExit (theCollider : Collider)
    57. {
    58.     if (theCollider.tag == "Player")
    59.     {
    60.         drawGUI = false;
    61.     }
    62. }
     
  18. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    transform.Translate will move the object by the Vector you passed in. You have to set the position as you had tried before, just don't write Spawner.position, simply spawner.

    And make several scripts.
    As i mentioned in a previous post, your function will most likely fail. You cannot load a new scene and expect that the next line of code would be executed in the new scene. You should really split the code. If my JS/US was better I'd do it for you, but you could do something similar to the example I posted. Have a script for the interior scenes and make them find the player and the spawn, and move it accordingly.
     
  19. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    The only issue with multiple scripts is in the main world (outside) we plan to have hundreds of these things enabling the user to jump into buildings, thats all well and good but how does it know which one is the correct point to jump back to to come out of the building?
    Before starting this, I had brainstormed a lot of potential problems but didn't think it would be THIS hard to get working.
    Although if I can get it working, it would be very rewarding.
     
  20. Suddoha

    Suddoha

    Joined:
    Nov 9, 2013
    Posts:
    2,824
    There are lots of way to do this. In my example I chose the most obvious one: When I entered somewhere, i stored the position where I want to come out again before I loaded the new scene, so when I go back into the main world, i simply use that data to get my position and rotation.
     
  21. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    This does seem like the best way to do this, but I think I said above, im mostly a 3D artist, this is just something I was sort of handed and told to get working, I am not very code-savy im afraid, and am not really sure how to go about implementing that into the script I have.

    In case the newest version isn't up here for everyone...

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var PlayerCharacter : Transform;
    4. var SpawnPoint : String = "";
    5. private var drawGUI = false;
    6. var Spawner : Vector3;
    7. var NewScene : String = "";
    8. var toText : String = "";
    9.  
    10. function Update ()
    11. {
    12. if (drawGUI == true && Input.GetKeyDown(KeyCode.F))
    13. {
    14.      LoadNewScene();
    15. }
    16. }
    17.  
    18. function OnTriggerEnter (theCollider : Collider)
    19. {
    20.     if (theCollider.tag == "Player")
    21.     {
    22.         drawGUI = true;
    23.     }
    24. }
    25.  
    26. function LoadNewScene ()
    27. {
    28.     DontDestroyOnLoad(PlayerCharacter);
    29.     Application.LoadLevel(NewScene);
    30.     yield WaitForSeconds (0.2);
    31.     Spawner = GameObject.Find(SpawnPoint).transform.position;
    32.     //Vector3 position = Spawner.transform;
    33.     PlayerCharacter.transform.Translate(Spawner);
    34.    
    35. }
    36.  
    37. function OnGUI()
    38. {
    39.     if (drawGUI == true)
    40.     {
    41.         //GUI.Label (Rect (Screen.width*0.5-0, 200, 120, 22), "Press F to open to");
    42.         //GUI.Label (Rect (Screen.width*0.5-35, 220, 150, 22), toText);
    43.        
    44.     //GUI.color = new Color(1,1,1,1.0f);
    45.     GUI.skin.box.fontSize=15;
    46.     GUI.backgroundColor = Color(0, 0, 0, 0);
    47.     GUI.BeginGroup (Rect (Screen.width / 2 - 75, Screen.height / 2 - 0, 150, 50));
    48.  
    49.     GUI.Box (Rect (0,0,150,25), "Press F to open to");
    50.     GUI.Box (Rect (0,22,150,25), toText);
    51.    
    52.     GUI.EndGroup ();
    53.     }
    54. }
    55.  
    56. function OnTriggerExit (theCollider : Collider)
    57. {
    58.     if (theCollider.tag == "Player")
    59.     {
    60.         drawGUI = false;
    61.     }
    62. }