Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. We are looking for feedback on the experimental Unity Safe Mode which is aiming to help you resolve compilation errors faster during project startup.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

(SOLVED) C# Getting The Current Scene's Name And Using It

Discussion in 'Scripting' started by Nikola310, Dec 11, 2015.

  1. Nikola310

    Nikola310

    Joined:
    Oct 24, 2015
    Posts:
    35
    Hello everoyne!
    I've posted my game onto GameJolt, and I want to add trophies.
    I know how to do THAT, but there's just one problem- I want to get a trophy when I load Level 3 (finish Level 2).
    Here is my script:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.SceneManagement;
    4.  
    5. public class APIScript : MonoBehaviour {
    6.  
    7.    
    8.     // Use this for initialization
    9.     void Start ()
    10.     {
    11.         if (GameJolt.API.Manager.Instance.CurrentUser == null)
    12.             {
    13.             GameJolt.UI.Manager.Instance.ShowSignIn ();
    14.             }
    15.     }
    16.    
    17.     // Update is called once per frame
    18.     void Update () {
    19.         if (Application.loadedLevelName = "Level3")
    20.         {
    21.             GameJolt.API.Trophies.Unlock (46732);
    22.  
    23.         }
    24.     }
    25.  
    26. }
    27.  
    I want to see if the scene loaded is Level 3 in the arguments of "if" in the "Update" function.
     
  2. matthewseaward

    matthewseaward

    Joined:
    Apr 12, 2013
    Posts:
    50
    Never worked with trophies before so I may be wrong. But shouldn't the trophy be earned for completing level 2 not starting level 3?

    So shouldn't the trophy be unlocked when the player has completed the objectives or the tasks for level 2. You haven't said what type of game it is - so some examples: If they reach the end of level 2, meet the time goal or reach the score goal - then the trophy could be unlocked?
     
  3. Nikola310

    Nikola310

    Joined:
    Oct 24, 2015
    Posts:
    35
    My game is Roll A Ball advanced (I added sounds, textures, music, UI's, more levels etc.). When getting 6 points you advance to the next level. I know that you can have something like if points = 6 && level=2 but I can't figure out how to get the level name and use it as a string.
     
  4. mikeymike

    mikeymike

    Joined:
    Oct 21, 2014
    Posts:
    35
    Code (csharp):
    1.  if(SceneManager.GetActiveScene().name=="Level3")
     
    Nikola310 likes this.
  5. Nikola310

    Nikola310

    Joined:
    Oct 24, 2015
    Posts:
    35
    Hmm,I'm getting no errors in the console..
    Thanks,I'll say if the trophy works in GameJolt once i release it.
    EDIT: It works!
     
    Last edited: Dec 11, 2015
unityunity