Search Unity

Can Someone Tell Me What Is Wrong With This Script?

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. BenZed

    BenZed

    Joined:
    May 29, 2014
    Posts:
    524
    How is it behaving other than how you would expect?

    I'm guessing that you're saying the player character is NOT kept when the new scene loads?

    If that's the case, try calling:

    Code (JavaScript):
    1. DontDestroyOnLoad(PlayerCharacter.gameObject);
    instead.

    Maybe it tags only the transform to keep, and when you dont tag the gameObject to keep, it destroys the transform anyway.
     
  3. Studio_Akiba

    Studio_Akiba

    Joined:
    Mar 3, 2014
    Posts:
    1,426
    Sorry, no the problem is the GUI does not appear (and I do have a GUI layer on the cam) and I am still not sure how to set the player to an objects transform that I would place where I needed it.
    I have moved this thread to here to see if it is easier for people to see:

    http://forum.unity3d.com/threads/skyrim-style-doors.287060/