JOB OFFER
I need a programmer who can help me with a scoring scripts. It is for a virtual reality app for teh oculus go devices.
Script 1: Score
This script counts the destroyed gameobjects in the game
Scripto 2: Total clicks
This script count the amount of clicks or attempts the user makes throughout the game
Both scripts are displayed on a canvas at the end of the game.
I pay for this job via Paypal
Interested send me email to rodrigo.cancino.82@gmail.com
From what you wrote, this should be roughly what you are looking for:
public class Scores : Monobehaviour
{
public static int destroyScore = 0;
public static int clickScore = 0;
// Call this if you need to reset the scores, ie when reloading a level or loading a new one
public static void Reset(){
destroyScore = 0;
clickScore = 0;
}
// For a score-object s call Scores.ScoreAndDestroy(s),
// instead of simply Destroy(s), to increment score and destroy the object
public static void ScoreAndDestroy(GameObject toDestroy){
Destroy(toDestroy);
destroyScore++;
}
// An approach like this works but is not exactly elegant, see below
public void Update(){
// If we detect a mouse button down, increment clickScore
if (Input.GetMouseButtonDown(0)){
IncrementClickScore();
}
}
// Instead of checking for mouse clicks each Update(), you could just use an EventTrigger component
// to call the below method OnMouseDown, which is more efficient than the Update() approach
public static void IncrementClickScore(){
clickScore++;
}
}
Untested since i cant really access my Unity installation right now. You’d attach the Scores component to an object and that’s basically it. Instead of destroying one of your score objects using the normal Destroy, now use Scores.ScoreAndDestroy(scoreObject). If you call Destroy from inside the object you want to destroy, that would be Scores.ScoreAndDestroy(this). The two scores are public and static, so you can access them globally using Scores.destroyScore or Scores.clickScore. You can concatenate these values to your score string and show it in some text field or something. Reset the scores back to 0 with the Reset() method.
There is a specific Unity forum for job offers as far as i know tho.