Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

loed level

Discussion in 'Scripting' started by ahmedalheday, May 5, 2014.

  1. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    i need a script that can load each level
    after the win text is shown
    or so
    if there is a script that can load each time the win text is shown
    i been trying to find videos on youtube and on google but it never seems to work
    so can some one help me pls
     
  2. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    http://pastebin.com/Hx4KWcDx#
    if this scpit coz come out at each time the wintext it showen
    is there a part of it i can add
    pls help me
    i am kind of a beginner on this
     
  3. SmokyZebra

    SmokyZebra

    Joined:
    Mar 13, 2014
    Posts:
    139
    I already told you, all you need is to use :


    Code (csharp):
    1. Application.LoadLevel(NumberOfTheLevelInBuild)
    U can, for exemple, put this on a button, like this :

    Code (csharp):
    1. function OnMouseDown(){
    2.  
    3.      Application.LoadLevel(NumberOfTheLevelInBuild)
    4.  
    5. }

    Remember that all your levels must be in your build, that you can acces through File/Build Settings.
    Or u can use some "if" statements to trigger the loading of the level.

    If you don't undrstand how to use that, redo some basic tutorials, you need it, because EVERY GAME IS DIFFERENT, you'll never find the exact script that you need and therefore need to understand the code you use and be able to make at least little modification to it.
     
  4. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    i know
    but i dont understand where to put the scpit in what part thats
    why
    and i am sorry for reposting the scrpit but wan i replay for u u dont replay back so thats why
     
  5. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    i know i been trying to find lot of videos but it gets harder and harder each time
    :(
    can u plss show me where i cud post the script ?
     
  6. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    I'm sorry to sound harsh, but you don't know programming, you barely know Unity, and you don't seem to understand English well enough to be able to ask sensible questions and understand the provided answers. How do you expect to finish whatever it is you're trying to do?

    What's your native language? I'm assuming from your forum name that it's either Arabic, Farsi, or Urdu. Maybe if you tell us that someone would be able to point you to a local user group where help would be more accessible to you.
     
  7. SmokyZebra

    SmokyZebra

    Joined:
    Mar 13, 2014
    Posts:
    139
    Where you have to put this line of code depend on your game. Maybe you have a score controller and want the game to end when you reach a certain score, let's say 100 in this case, you would have to put in a script :


    Code (csharp):
    1. function Update(){
    2.  
    3.      if(score >= 100){
    4.  
    5.           Application.LoadLevel(NumberOfTheLevelInBuild)
    6. }
    7.  
    8. }
    But if you want the game to end with other condition, you have to change the if statement.
     
  8. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    ok
    this is the player script its C#
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class BallScript : MonoBehaviour
    5. {
    6.    
    7.     public float speed;
    8.     public GUIText countText;
    9.     public GUIText wintext;
    10.     private int count;
    11.    
    12.     void Start ()
    13.     {  
    14.         count = 0;
    15.         SetCountText ();
    16.         wintext.text = "";
    17.     }
    18.    
    19.     void FixedUpdate ()
    20.     {
    21.         float moveHorizontal = Input.GetAxis ("Horizontal");
    22.         float moveVertical = Input.GetAxis ("Vertical");
    23.        
    24.         Vector3 movement = new Vector3 (moveHorizontal, 0.0f, moveVertical);
    25.        
    26.         rigidbody.AddForce (movement * speed * Time.deltaTime);
    27.     }
    28.    
    29.     void OnTriggerEnter(Collider other)
    30.     {
    31.         if(other.gameObject.tag == "PickUp")
    32.         {
    33.             other.gameObject.SetActive(false);
    34.             count = count + 1;
    35.             SetCountText ();
    36.         }
    37.     }
    38.    
    39.     void SetCountText ()
    40.     {
    41.         countText.text = "Count: " + count.ToString();
    42.         if(count >= 12)
    43.         {
    44.             wintext.text = "YOU WIN";
    45.         }
    46.     }
    47. }
    where do i add the script in it or do i have to make a java one ?

    [edit: Added code tags - Admin]
     
  9. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    this is the levels one that i am trying to make it pop out at the end of each game

    Code (csharp):
    1. var boxbg : Texture2D;
    2. var SceneOne : String;
    3. var SceneOneName : String = "Level One";
    4. var SceneTwo : String;
    5. var SceneTwoName : String = "Level Two";
    6. var SceneThree : String;
    7. var SceneThreeName : String = "Level Three";
    8.  
    9.  
    10. function OnGUI()
    11. {
    12.         GUI.BeginGroup (Rect (Screen.width/2-50, Screen.height/2-50, Screen.width, Screen.height));
    13.         GUI.Box (Rect (0,0,150,200), boxbg);
    14.         if (GUI.Button(Rect(10,10,125,30),SceneOneName))
    15.         {
    16.                 Application.LoadLevel(SceneOne);
    17.         }
    18.         if (GUI.Button(Rect(10,50,125,30),SceneTwoName))
    19.         {
    20.                 Application.LoadLevel(SceneTwo);
    21.         }
    22.         if (GUI.Button(Rect(10,90,125,30),SceneThreeName))
    23.         {
    24.                 Application.LoadLevel(SceneThree);    
    25.         }
    26.         if (GUI.Button(Rect(10,130,125,30),"Quit"))
    27.         {
    28.                 Application.Quit();
    29.         }
    30.         GUI.EndGroup();
    31. }
    this one is a java script

    [edit: Added code tags - Admin]
     
  10. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    sir there is ways of learning
    there is learning by book and there is learning by experience
    so i am learning both ways
    and what ever is that i am doing is not of your worries sir your not going to play it
    so dont be Quick to Judge on some things that u may not understand
     
  11. shaderop

    shaderop

    Joined:
    Nov 24, 2010
    Posts:
    942
    Do you classify posting the same question over and over again as book learning or experience? Because I think most people would say it's neither.

    I'm not worried at all. Thank you for your concern though.

    Irony!

    Good luck, dude.
     
  12. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    yes i do post the same question over and over and over again to maybe get a better reply
    your welcome and i had no concerns
    and good luck to u to sir
     
  13. Fluzing

    Fluzing

    Joined:
    Apr 5, 2013
    Posts:
    815
    You are not at the correct level of Unity programming to be concerned with changing levels. Start with the basics first, because loading a level is quite trivial and if you do not know how to do that, there is probably a lot more you need to learn first.
     
  14. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    yes i do know and i am going thru with basics
     
  15. S3dition

    S3dition

    Joined:
    Jan 6, 2013
    Posts:
    252
    The basics include conditionals. If you understand conditionals then you would know where to load new levels from.

    http://unity3d.com/learn/tutorials/modules/beginner/scripting

    You NEED to watch all of those, because what you're asking for is #5 on the list. That's very, very basic coding. Don't worry about multiple levels until you understand how to code one.
     
  16. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    i do know what conditionals mean sir

    and yes i am but in some points i dont understand what do they mean
     
  17. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    You can start by:

    A) using
    Code (csharp):
    1.  tags around your code on forum so people can read it better
    2. B) stop arguing with forum members. Just focus on the code :)
     
  18. ahmedalheday

    ahmedalheday

    Joined:
    Feb 24, 2014
    Posts:
    103
    ok but i haven't started it they did