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\$
  • \$\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 Jan 30 '19 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 Jan 30 '19 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\$ – Shuvro Sarkar Jan 31 '19 at 1:19
  • \$\begingroup\$ Have you checked wheater the text component is large enough to store the word "score" and a number? \$\endgroup\$ – user115399 Jan 31 '19 at 6:23
  • \$\begingroup\$ @GabrieleVierti the word score is going to be replaced with just the number \$\endgroup\$ – Indiepixel Feb 5 '19 at 0:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.