• 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 hellgas · Jul 03, 2014 at 03:50 AM · javascriptscorepongpaddle

Scoring not working for pong

on either side of the walls the score always goes to Player02 i have tried everyt$$anonymous$$ng to change it but not$$anonymous$$ng works

t$$anonymous$$s is the code below i have tried many methods especially with the PlayerScore01 += 1

 #pragma strict
 
 static var playerScore01 : int = 0;
 
 static var playerScore02 : int = 0;
 
 var theSkin : GUISkin;
 
 static function Score (wallName : String) {
 
     if (wallName == "Right Wall")
     {
         playerScore01 += 1;
     }
     else if (wallName == "Left Wall")
         playerScore02 += 1;
     }
     Debug.Log("Player Score 1 is " + playerScore01);
     Debug.Log("Player Score 2 is " + playerScore02);
 
 function OnGUI () {
     GUI.skin = theSkin;
     GUI.Label (new Rect (Screen.width/2-150, 25, 100, 100), "" + playerScore01);
     GUI.Label (new Rect (Screen.width/2+150, 25, 100, 100), "" + playerScore02);
 }








Comment
Add comment · Show 4
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 NoseKills · Jul 03, 2014 at 04:49 AM 1
Share
avatar image hellgas · Jul 03, 2014 at 12:49 PM 0
Share
avatar image Josh Naylor ♦♦ · Jul 03, 2014 at 01:17 PM 0
Share
avatar image hellgas · Jul 03, 2014 at 04:17 PM 0
Share

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Entwicklerpages · Jul 03, 2014 at 06:00 PM

First, is your wall correctly named? And is the trigger at the correct position? Maybe you have duplicated the wall for player1 and forgot to move it to the right location.

Also, I t$$anonymous$$nk you don't should use the name of the gameobject. I t$$anonymous$$nk using a bool or int is a better choice. And in the trigger script get the right value with a public var. (You can change the value of a public variable in the inspector).

 public var player : int = 1;
 
 function OnTriggerEnter2D ($$anonymous$$tInfo : Collider2D) {
     if ($$anonymous$$tInfo.name == "Ball")
     {
         GameManager.Score (player);
     }
 }

And in the GameManger script change the parameter from String to int.

 static function Score (plrNo : int) {
  
     if (plrNo == 1)
     {
         playerScore01 += 1;
     } else if (plrNo == 2) {
         playerScore02 += 1;
     }
     Debug.Log("Player Score 1 is " + playerScore01);
     Debug.Log("Player Score 2 is " + playerScore02);
 }

PS: You have forgotten the closing bracket in the Score function. Look at my script. You have also forgotten the opening bracket for the else if

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 hellgas · Jul 06, 2014 at 11:11 PM 0
Share

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

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Score Keeper / Kill Counter Help 1 Answer

Score Help!!!! 2 Answers

In my pong game How do I prevent paddle from going threw walls? 1 Answer

Help with score 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