• 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
-2
Question by Brennan · Jun 26, 2010 at 06:31 AM · score

How to set a score limit?

I am currently making a army game and wanted to know how to make it where the game ends when a score limit is reached? and if anyone knew how to make a spectator view for those players who aren't playing?

Comment
Add comment · Show 2
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 qJake · Jun 26, 2010 at 06:32 AM 0
Share

Don't ask more than one question in a single post. And try to b a little more specific with your questions, if you ask a broad question, all you're going to get is a broad answer.

avatar image qJake · Jun 26, 2010 at 06:33 AM 0
Share

Also, please choose better tags for your question. Copying and pasting the title into the tags field is not helpful in the least. If you're new to UnityAnswers, please read the FAQ before you do anything else: http://answers.unity3d.com/faq

2 Replies

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

Answer by MikezNesh · Jun 26, 2010 at 01:50 PM

The script for reaching score to end level would be:

var score = 0;

if(score >= 1000) { Application.LoadLevel ("levelname"); }

You still need to add how to earn points in this case. Also Application.LoadLevel is just changing scenes and you can choose which scene to change to.

So the scene you load could be your lobby or level select depending on if this game is multi-player or single.

An example of earning points after killing would be:

score += 100;

Hope this helps. :)

EDIT: Answering comment.

Application.LoadLevel(Random.Range(0, Application.levelCount));

This code just goes through your level list and selects one.

Comment
Add comment · Show 5 · 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 Brennan · Jun 26, 2010 at 05:52 PM 0
Share

do you perhaps know how to make it randomly select a level?

avatar image MikezNesh · Jun 27, 2010 at 12:20 AM 0
Share

Ok edited code to answer your next question. Don't forget to vote up and check this answer if you found it helpful :P

avatar image Cyclops · Jun 27, 2010 at 06:33 PM 0
Share

@$$anonymous$$ikezNesh, reformatted your code - FYI, the code format button is that "1010101" button.

avatar image MikezNesh · Jun 28, 2010 at 12:49 AM 0
Share

yeah...I tried it but in my preview it doesn't work. Dont know why...

avatar image Cyclops · Jun 28, 2010 at 02:27 PM 0
Share

@$$anonymous$$ikezNesh, it is glitchy, and sometimes doesn't immediately show in the Preview, but it will be there for the Answer. Also try clicking in the Preview and waiting a few seconds, sometimes it updates. (And I suspect may also break it, I always use spaces.)

avatar image
0

Answer by netzunity · Oct 15, 2016 at 01:55 PM

@MikezNesh This is my codes on my Table Tennis Ball. where can i put the Scoring Limit code?

using UnityEngine; using System.Collections;

public class PingPong_Ball : MonoBehaviour {

 public AudioClip[] blipAudio;
 public int factor;

 public bool reset = false;

 public Human_Player userBatScript;
 public AI_Player aiBatScript;

 public string batStatus;

 private float speed = 12;
 private Vector3 firstpostion;
 private bool firstServe;
 private Transform batTransform;
 private int groundCount;
 private string tableSideName;

 void Start () {
     firstpostion = transform.position;
 }

 public void Reset()
 {
     reset = false;

     GetComponent<Rigidbody>().useGravity = false;
     GetComponent<Rigidbody>().velocity = Vector3.zero;
     transform.position = firstpostion;
     aiBatScript.Reset();
     userBatScript.Reset();

 }
 
 
 public void Serve(Transform t)
 {
     if(Random.Range(1,3) == 1)
     {
         factor = -1;
     }
     else
     {
         factor = 1;
     }
     reset = true;

     GetComponent<Rigidbody>().useGravity = true;
     GetComponent<Rigidbody>().AddForce(Vector3.down*2.7f,ForceMode.Impulse);
     GetComponent<Rigidbody>().AddForce(transform.forward*speed,ForceMode.Impulse);

     if(Random.Range(1,3) == 1)
         GetComponent<Rigidbody>().AddForce(transform.right*0.4f*2,ForceMode.Impulse);
     else
         GetComponent<Rigidbody>().AddForce(transform.right*-0.4f*2,ForceMode.Impulse);

     firstServe = true;
     batTransform = t;
 }

 void OnCollisionEnter(Collision collisionInfo) {
     AudioSource.PlayClipAtPoint (blipAudio [0], transform.position);

     if(collisionInfo.collider.name == "UserSideTable")
     {
             userBatScript.RegisterSpin();
             tableSideName = "UserSideTable";
     }

     if(collisionInfo.collider.name == "AiSideTable")
     {
         if(firstServe)
         {
             batTransform.GetComponent<Collider>().isTrigger = false;
             batTransform.GetComponent<Rigidbody>().isKinematic =true;
             batTransform.GetComponent<Human_Player>().firstServe = false;
             firstServe = false;
         }

         tableSideName = "AiSideTable";
     }

     if(collisionInfo.collider.name == "Wall")
     {
         groundCount++;
         if(groundCount == 2)
         {
             Reset();
             groundCount = 0;

             if(batStatus == "abat")
             {
                 if(tableSideName == "UserSideTable"){
                         //AI_Player.points++;
                     AI_Player.AddPoints();
                         //CameraFollow.aiPoints = AiBat.points.ToString();
                 }
                 if(tableSideName == "AiSideTable"){
                         //Human_Player.points++;
                     Human_Player.AddPoints();
                         //CameraFollow.userPoints = UserBat.points.ToString();
                 }
             }

             if(batStatus == "ubat")
             {
                 if(tableSideName == "AiSideTable"){
                         //Human_Player.points++;
                     Human_Player.AddPoints();
                         //CameraFollow.userPoints = UserBat.points.ToString();
                 }
                 if(tableSideName == "UserSideTable"){
                         //Human_Player.points++;
                     Human_Player.AddPoints();
                         //CameraFollow.aiPoints = AiBat.points.ToString();
                 }
             }
         }
     }
 }

}

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.

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

1 Person is following this question.

avatar image

Related Questions

Scoring System/Clock? 4 Answers

Score script player dissapearing 3 Answers

score not add in the gui text 2 Answers

Score multiplier/ chaining system 1 Answer

how to save score in a system as a file in unity3d 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