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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

I need help with my level up script and game over script (SCRIPT INCLUDED)

Discussion in 'Scripting' started by davidbartlomiej21, Sep 20, 2018.

  1. davidbartlomiej21

    davidbartlomiej21

    Joined:
    Sep 19, 2018
    Posts:
    5
    I need help using my levelUp script with my GameOverCommand script. My goal is to have the player gain 200 exp after each game, how can I achieve this? I have attached the scripts below, please any help will be very appreciated.

    [LevelUp Script]


    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class LevelUp : MonoBehaviour {


    public int level;
    private float experience;
    private float experienceRequired;



    void Start ()
    {
    level = 1;
    experience = 0;
    experienceRequired = 100;
    }

    void Update ()
    {



    Exp();

    if (Input.GetKeyDown (KeyCode.Q))
    {
    experience += 100;
    }

    }

    void RankUp()
    {
    level += 1;
    experience = 0;

    switch (level) {
    case 2:
    experienceRequired = 200;
    break;

    case 3:
    experienceRequired = 200;
    break;

    }
    }

    void Exp()
    {
    if (experience >= experienceRequired)
    RankUp();
    }
    }





    [GameOverCommand Script]


    using UnityEngine;
    using System.Collections;

    public class GameOverCommand : Command{

    private Player looser;

    public GameOverCommand(Player looser)
    {
    this.looser = looser;
    }

    public override void StartCommandExecution()
    {
    looser.PArea.Portrait.Explode();
    }
    }
     

    Attached Files:

  2. jaclark

    jaclark

    Joined:
    Sep 29, 2014
    Posts:
    19
    What's the problem you're having? Your scripts look ok.
    Is it a matter of being able to change the experience value from the GameOverCommand script? If so, you could pass your instance of LevelUp into GameOverCommand:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class GameOverCommand : Command
    5. {
    6.      private Player looser;
    7.      private LevelUp levelUp;
    8.  
    9.      public GameOverCommand(LevelUp levelUp, Player looser)
    10.      {
    11.           this.looser = looser;
    12.           this.levelUp = levelUp;
    13.      }
    14.  
    15.      public override void StartCommandExecution()
    16.      {
    17.           looser.PArea.Portrait.Explode();
    18.           levelUp.AddExperience(100);
    19.      }
    20. }