Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by MrTerkyMan · May 16, 2019 at 02:43 AM · scorescore systemmanagercontrollers

Help With Score Controller - Can You Only Have One?

Hey all, fairly new to Unity development. I am working on a game with increasing score requirements each level to advance on. I have this script controlling score

 public Text scoreText;
 public int score;

 public void Start()
 {
     score = 0;
     UpdateScore();
 }

 public void AddScore (int newScoreValue)
 {
     score += newScoreValue;
     UpdateScore();
     if(score >= 7)
     {
         SceneManager.LoadScene(4);
     }
     
 }

 void UpdateScore()
 {
     scoreText.text = "Items Placed: " + score + "/7";
 }

This is linked with an item dropping script that adds a point when you interact with the correct items in the scene. It is attached to the empty game manager object and when the item drop script asks for a score controller in the editor, the manager object is placed in said slot.

The issue is, I'm not sure how to make a single script to handle multiple different level's scores so I recreated the same 2 scripts for the second level and changed the int value and corresponding scene to move to afterwards, however, when this score script is added to the manager in the new scene it won't let me slot it into the item drop script in the editor. I am totally baffled and any help would be appreciated. Here is the code in the item drop script if it helps, but it may not out of context.

 public Item dropItem;
 public GameObject placeHolderObject;
 public int scoreValue = 1;
 public ScoreController scoreController;

 public override void Interact()
 {
     base.Interact();

     Item itemToDrop = Inventory.instance.Remove(dropItem);

     if (itemToDrop != null)
     {
         Instantiate(itemToDrop.itemObject, placeHolderObject.transform.position, placeHolderObject.transform.rotation);
         placeHolderObject.SetActive(false);
         hasInteracted = true;
         scoreController.AddScore(scoreValue);
     }
     else
     {
         Debug.Log("You no have item click click click");
         hasInteracted = false;
     }

 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by CoryButler · May 17, 2019 at 02:33 PM

Add a public int requiredScore field, and use this variable in place of the hard-coded 7 you are currently using. Likewise, replace the 4 with a public int sceneId. You can then set the required score and the ID of the scene to load on the empty game object per scene, instead of adding a custom script per scene.

Additionally, as long as the class is named ScoreController, and the manager is looking for an object of type ScoreController this should resolve the second issue you mentioned as well.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

109 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to check if an object has rotated around itself (360° in x,y,z) 1 Answer

my code is suppose to store high score and its storing recent score insted and it wont stop if game over and it has an score counter as well plzz help 0 Answers

Save/Add score while different level load 1 Answer

How to add score after destroying object in unity 2D? 1 Answer

Add score when enemy is killed? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges