x


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.

more ▼

asked Apr 20 '12 at 12:10 AM

Kandak gravatar image

Kandak
0 2 2 3

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first
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.

more ▼

answered Apr 20 '12 at 02:29 AM

Flash gravatar image

Flash
183 1 2 5

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!

Apr 20 '12 at 08:59 PM Kandak

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); }

Apr 20 '12 at 11:37 PM Flash
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x799
x418
x205
x132

asked: Apr 20 '12 at 12:10 AM

Seen: 574 times

Last Updated: Apr 20 '12 at 11:37 PM