0
\$\begingroup\$

Hello I'm working on a game with random generation, a dungeon crawler of sorts. i need to be able to have an object that when instantiated, adds to the score(the goal is to find all of them as the dungeon is created around you)this is the script for the orb/cube.`

public Text score;
public int scores;


// Use this for initialization
void Start () {
    scores ++ ;

    score.text = scores.ToString();
}
public void Update()
{
    score.text = scores.ToString();
}




public void OnMouseDown()
{
    Destroy(gameObject);

    scores--;
}

`

when an object is added it won't add to the score.enter image description here

\$\endgroup\$
5
  • \$\begingroup\$ The int called 'scores' should be static, and it should be inside of another class. That way, whenever the prefab is instantiated, the same score is being incremented/decremented by that object. \$\endgroup\$
    – Sean Carey
    Commented Jan 30, 2019 at 23:49
  • \$\begingroup\$ ok, but then that brings up the question about, how do I grab the value from the int in another class \$\endgroup\$
    – Indiepixel
    Commented Jan 30, 2019 at 23:56
  • \$\begingroup\$ 1. Create a New C# Script. Name it Something relevant.(e.g. ScoreManager) 2. Do all the functions for the score inside that Script. Then Create a new gameobject in the editor and add the script to it. 3. From this class where u are instantiating the objects Call the ScoreManager by simply ScoreManager.score(Assuming that score is static) \$\endgroup\$ Commented Jan 31, 2019 at 1:19
  • \$\begingroup\$ Have you checked wheater the text component is large enough to store the word "score" and a number? \$\endgroup\$
    – user115399
    Commented Jan 31, 2019 at 6:23
  • \$\begingroup\$ @GabrieleVierti the word score is going to be replaced with just the number \$\endgroup\$
    – Indiepixel
    Commented Feb 5, 2019 at 0:31

0

You must log in to answer this question.

Browse other questions tagged .