- Home /
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 () {
}
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);
}
}
Your solution will increase the score on every hit though. Not just on destruction.
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);
}
}
thanks you gjallanhorn worked like a charm! thank you grim darknight i also put what you said into the script
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
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
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
Follow this Question
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