when object destroyed send points

How would I write a script that when my metor is stroyed it sends points to scoreing script called Highscores. I want to do this in c# as its what all my other scripts are in. I am a bit new to c# but am slowing learning it.

Here is my highscore script I have.

Its called Highscore.cs

	public string secretKey = "12345";
	public string PostScoreUrl = "http://YouWebsite.com/.../postScore.php?";
	public string GetHighscoreUrl = "http://YouWebsite.com/.../getHighscore.php";

	public string name = "";
	public int score;
	private string WindowTitel = "";
	public string Score = "";


	public int maxNameLength = 10;
	public int getLimitScore = 15;
	
	 public int score1 = 0;
		
	private bool start = false;
	

	public float timer = 60;

	
	   public string stringToEdit = "Your Name";
	

	
	



	
	void Update () 
	{
		
		timer -= Time.deltaTime;

		if (timer <= 0 && start == false)
	
		{
			
			
			StartCoroutine(PostScore(name,score));
       		name = stringToEdit;
      		score = score1;
			
			start = true;
			
			
		}
				
		
	}
	
	IEnumerator GetScore()
	{
		Score = "";
			
    	WindowTitel = "Loading";
		
		WWWForm form = new WWWForm();
		form.AddField("limit",getLimitScore);
		
    	WWW www = new WWW(GetHighscoreUrl,form);
    	yield return www;
		
		if(www.text == "") 
    	{
			print("There was an error getting the high score: " + www.error);
			WindowTitel = "There was an error getting the high score";
    	}
		else 
		{
			WindowTitel = "Done";
       		Score = www.text;
		}
	}
	
	 IEnumerator PostScore(string name, int score)
	{
		string _name = name;
		int _score = score1;
		
		string hash = Md5Sum(_name + _score + secretKey).ToLower();
		
		WWWForm form = new WWWForm();
		form.AddField("name",_name);
		form.AddField("score",_score);
		form.AddField("hash",hash);
		
		WWW www = new WWW(PostScoreUrl,form);
		WindowTitel = "Wait";
		yield return www;
		
    	if(www.text == "done") 
    	{
       		  Application.LoadLevel("HighScore");
    	}
		else 
		{
			print("There was an error posting the high score: " + www.error);
			WindowTitel = "There was an error posting the high score";
		}
	}
	
	void OnGUI()
	{
		
		GUI.Label(new Rect (10, 10, 1000, 20), "Score: " + score1);
		
		
		 stringToEdit = GUI.TextField(new Rect(Screen.width/2, Screen.height/2, 200, 50), stringToEdit, 25);
		name = stringToEdit;
		
		
   
	}
	

	
	public string Md5Sum(string input)
	{
    	System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
    	byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
    	byte[] hash = md5.ComputeHash(inputBytes);
 
    	StringBuilder sb = new StringBuilder();
    	for (int i = 0; i < hash.Length; i++)
    	{
    	    sb.Append(hash*.ToString("X2"));*
  • }*

  • return sb.ToString();*

  • }*

  • public void increaseScore(int _value)*
    {
    score1 += 11;
    }

}

Do you already written your Highscores.cs?

in a simple way, you should have one object in your scene that have the Highscores component. And that object should have a unique tag like “highscoremanager”

Then, all your meteors (or other “enemy”) should have a reference to that Highscores component.

In your Meteor.cs you should:


//This is Meteor script

Highscores localHighscoresReference;
int currentHealth = 10;
int scoreValue = 100;    
    
Start()
{
   localHighscoresReference = GameObject.FindGameObjectWithTag("highscoremanager").GetComponent<Highscores>();
}

void takeDamage(int _damage)
{
  currentHealth -= _damage;

  if (currentHealth <= 0)
       killThisObject();
}

void killThisObject()
{ 
  localHighscoresReference.increaseScore(scoreValue);
}

//You will need some collision detection (trigger or no)  to call the "takeDamage(int)" method. The damage should come from the shot.

Then on your highscores.cs:


int currentScore = 0;

public void increaseScore(int _value)
{
  currentScore += _value;
}

It should get it working. Just make sure the collision detection ins working.