Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 magnusOP · Oct 04, 2013 at 09:30 PM · collisiondestroyscorecounterpoints

Scoring (i'm stuck)

hey guys i have a scoring system that i would like to get working. whats supose to happen when the bubble is destroyed bye a raycast it has to add up into my point system script i have if you guys can help me out i would really appreciate it!

 #pragma strict
 
 static var score : int = 0;
 
 
  
     function OnCollisionEnter ( collision : Collision)
     {
         if (collision.gameObject.tag == "bubble"){
         score += 1;
         
      
         
         }
        
     
     }
 
 
 function OnGUI()
 {
      GUI.Label( Rect(Screen.width - 90, Screen.height -35, 100, 20), "Points: " + (score));
     
 }
 
 function Update () {
   
     }
 
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 Gjallanhorn · Oct 04, 2013 at 10:01 PM 0
Share

when you say raycast, you mean click of the mouse?

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Gjallanhorn · Oct 04, 2013 at 11:03 PM

You're using OnCollisionEnter(), but you have nothing colliding, that's the problem, just

increase the score, when you get the touch:

function Update(){ for (var touch : Touch in Input.touches) { if (touch.phase == TouchPhase.Began) {

         var ray = camera.ScreenPointToRay(touch.position);
         var hit : RaycastHit;
         if (Physics.Raycast (ray, hit, 400))
         {

 <SCRIPT WHERE THIS VAR IS (IF IT IS OUTSIDE THIS)>.score += 1;
             hit.transform.SendMessage("DecHealth", 1, SendMessageOptions.DontRequireReceiver);
         }
     }
 }

}

Or put it inside the DecHealth():

 function DecHealth(howMany: int)
 {
     <SCRIPT WHERE THIS VAR IS (IF IT IS OUTSIDE THIS)>.score += 1;
     Health -= 1;
     if (Health <= 0){ 
         Destroy(gameObject);
     }
 }
Comment
Add comment · Show 3 · 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 Grim_Darknight · Oct 04, 2013 at 11:06 PM 0
Share

Your solution will increase the score on every hit though. Not just on destruction.

avatar image Gjallanhorn · Oct 04, 2013 at 11:09 PM 0
Share

put the score increase line inside of the If..

 function DecHealth(how$$anonymous$$any: int)
 {
     
     Health -= 1;
     if (Health <= 0){ 
     <SCRIPT WHERE THIS VAR IS (IF IT IS OUTSIDE THIS)>.score += 1;
         Destroy(gameObject);
     }
 }
avatar image magnusOP · Oct 09, 2013 at 06:23 PM 0
Share

thanks you gjallanhorn worked like a charm! thank you grim darknight i also put what you said into the script

avatar image
0

Answer by magnusOP · Oct 04, 2013 at 10:54 PM

no OnMouseButtonDown its a raycast here is the script that is place on my camera

 function Update(){
     for (var touch : Touch in Input.touches) 
     {
         if (touch.phase == TouchPhase.Began) 
         {
             
             var ray = camera.ScreenPointToRay(touch.position);
             var hit : RaycastHit;
             if (Physics.Raycast (ray, hit, 400))
             {
                 
                 hit.transform.SendMessage("DecHealth", 1, SendMessageOptions.DontRequireReceiver);
             }
         }
     }
 }


script place on my bubbles for health and how many taps to kill.

 unction Start()
 {
     if (bubbleEasy == true){ 
         Health = 1;
     }
     else if (bubbleMed == true){
         Health = 2;
     }     
     else if (bubbleHard == true){
         Health = 3;
     }
 }
  
 function DecHealth(howMany: int)
 {
     Health -= 1;
     if (Health <= 0){ 
         Destroy(gameObject);
     }
 }
  
 function OnDestroy (){
     tapCount += 1;
 }



any help would be great thanks guys

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

Answer by Grim_Darknight · Oct 04, 2013 at 10:21 PM

if you already have the buble destruction set up you can put

 function OnDestroy()
 {
     ContainingScript.score += 1;
 }

in a script attatched to each bubble

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 Grim_Darknight · Oct 04, 2013 at 11:00 PM 0
Share

On the bubble just add an increase to the score in the buble's OnDestroy() function.

Since score is static all you neet to do is replace ContainingScript with the name of the script that score is defined in.

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

17 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

Related Questions

Question about Point adding / Destroying after collision. 0 Answers

Is there another way of counting Scores (points) instead of Colliding (destroying) 1 Answer

Help scoring Points In a Jousting game 1 Answer

how to keep track of bricks broken 1 Answer

Collision with cube isn't working when Instantiate clone it 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