• 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 /
  • Help Room /
avatar image
0
Question by vaders_girl · Feb 24, 2016 at 02:19 AM · c#scripting problemenemyscorebullet

Score counter not working properly.

Heya, I am new to Unity and c# ... I am just making a simple vertical shooter and am now up to keeping score! I just want to score 1 point each time an enemy is destroyed (all it takes is one shot from the bullet). Now at the moment, what my score counter is doing is scoring a point each time you hit the enemy, however if you miss the enemy, say 3 times in a row, the score will tally up for when you next hit the enemy.. So you could be on 1 point, miss three times, then hit an enemy and your score will go from 1 to 4 . I tried changing the score codes from the EnemyScript and putting it instead in the BulletScript, but no change. I think it's something simple I am missing but I am not sure what it is! Any help would be appreciated.. Here is my bullet script as it stands currently:

using UnityEngine; using UnityEngine.UI; using System.Collections;

public class BulletScript : MonoBehaviour {

 public float BulletSpeed = 5f;
 public PlayerController playerController;
 public int Count;
 public Text CountText;


 void Update () { 
     transform.Translate (Vector3.up * BulletSpeed * Time.deltaTime);

 }
 void OnBecameInvisible () { 
     this.gameObject.SetActive (false);
 }

 void OnTriggerEnter2D(Collider2D other)
 {

     if (other.gameObject.tag == "Enemy")
         gameObject.SetActive (false);

     playerController.CountText.text = playerController.Count.ToString();


 }

 void Start() { 
     playerController = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();

 }

}

Thank you!

Comment
Add comment · Show 1
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
avatar image jgodfrey · Feb 24, 2016 at 02:24 AM 0
Share

So, it looks like you track your score in the "playerController.Count" variable? If that's the case, where is that variable incremented? It doesn't happen in the posted code.

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by TreyH · Feb 24, 2016 at 02:30 AM

 playerController.Count++;
 playerController.CountText.text = playerController.Count.ToString();

? You weren't incrementing anywhere here. :-)

Comment
Add comment · Show 1 · 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
avatar image vaders_girl · Feb 24, 2016 at 06:10 AM 0
Share

Ah! Thank you so much. As I said I am quite new to this and after playing around with it for a while I completely forgot to add that part back in! Thank you :) :)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

116 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

PlayerScore prefab in unity gives value in gameover screen as 0, how do I show the final value in GameOver scene? 0 Answers

NEED HELP PLEASE! Unexpected symbol. 0 Answers

Score value in GameOver screen is 0 instead of final value from the Game Level scene(used PlayerPrefs), how do I display the final value from Game Level scene in the GameOver scene? 1 Answer

Bullet doesn`t die when enemy destory 1 Answer

How to kill enemy when the bullet hits the BoxColllider2D? 1 Answer


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