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 Kandak · Apr 20, 2012 at 12:10 AM · gamecarsystempoint

point system for car game

Hi! I want to make a point system for my car game. Here is the code for jumping tricks (pretty simple)

 using UnityEngine;

using System.Collections;

public class Jumping : MonoBehaviour { public GameObject nissan350z;

 // Use this for initialization
 void Start () {
 
 }
 
 // Update is called once per frame
 void Update () {
 if(Input.GetKey("1"))
     {
     transform.Rotate(Vector3.forward * (100*Mathf.PI) * Time.deltaTime);
     }
     if(Input.GetKey("2"))
     {
     transform.Rotate(Vector3.up * (100*Mathf.PI) * Time.deltaTime);
     }
     if(Input.GetKey("3"))
     {
     transform.Rotate(Vector3.down * (100*Mathf.PI) * Time.deltaTime);
     }
     if(Input.GetKey("4"))
     {
     transform.Rotate(Vector3.left * (100*Mathf.PI) * Time.deltaTime);
     }
     if(Input.GetKey("5"))
     {
     transform.Rotate(Vector3.right * (100*Mathf.PI) * Time.deltaTime);
     }
     

} }

So I wondering if it's possible to make a system that each time I push 1,2,3,4 or 5, and land properly, I should get a certain amount of points. Thanks, any help will appreciated. PS: I am new in coding/scripting.

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 Flash · Apr 20, 2012 at 02:29 AM

 using UnityEngine;
 using System.Collections;
 
 public class Jumping : MonoBehaviour { public GameObject nissan350z;
 
     private int tmpScore = 0;
     
     // Update is called once per frame
     void Update () {
         if(Input.GetKey("1"))
           {
             transform.Rotate(Vector3.forward * (100*Mathf.PI) * Time.deltaTime);
             tmpScore += 5;
         }
         if(Input.GetKey("2"))
         {
             transform.Rotate(Vector3.up * (100*Mathf.PI) * Time.deltaTime);
             tmpScore += 10;
         }
         if(Input.GetKey("3"))
         {
                transform.Rotate(Vector3.down * (100*Mathf.PI) * Time.deltaTime);
             tmpScore += 15;
         }
         if(Input.GetKey("4"))
         {
             transform.Rotate(Vector3.left * (100*Mathf.PI) * Time.deltaTime);
             tmpScore += 20;
         }
         if(Input.GetKey("5"))
         {
                transform.Rotate(Vector3.right * (100*Mathf.PI) * Time.deltaTime);
             tmpScore += 25;
         }
     }
     
 }

This code will add 5,10,15,20,25 relative to the number keys pressed (1,2,3,4,5) to a tmpScore variable. Now what you need is a way to determine if the car has landed properly... This could be done with colliders/triggers under the car or through a more complicated script. Once the car has landed properly you will need to add the tmpScore to the current score of your player.

 score += tmpScore

I will need more information about the game (Probably need to see a live demo) in order to figure out which solution would be best for checking if the car lands properly.

Comment
Add comment · Show 2 · 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 Kandak · Apr 20, 2012 at 08:59 PM 0
Share

Thank you veyr much for your reply!

I have 4 wheelcolliders, so I was thinking, if a player lands properly with atleast 1 wheel on the terrain, he gets points for that. And the points should be counted in the small gui box.

I hope you will be able to help me with that. Thanks in advance!

avatar image Flash · Apr 20, 2012 at 11:37 PM 0
Share

You can try something like this.

function OnCollisionEnter(collision : Collision) { if(collision.gameObject.name == "terrain"){ //Add score to player. } }

Here's more help on OnCollisionEnter: http://unity3d.com/support/documentation/ScriptReference/Collider.OnCollisionEnter.html Here's some info about the Collision: http://unity3d.com/support/documentation/ScriptReference/Collision.html

As for displaying the score on screen simply use:

function OnGUI(){ GUI.Label(Rect(10, 10, 100, 25), "Score: "+Score); }

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Point system for car game 0 Answers

Accessing local system ( File Browser ) 2 Answers

Car Script error C# 2 Answers

game system requirements 1 Answer

Simple Point system 3 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