Adding coin score to multiplied value

I have a script that causes the score that goes up by 100 every second, and a script that should add 1000 points every coin collided with. Both scripts run, however when the player collides with the coin, 1000 points isn’t added to the current score.

Here is my script for score per second:

using UnityEngine;
using System.Collections;
public class ScoreperSec : MonoBehaviour {
	public int startingScore = 0;
	public int currentScore = 0;
	public GUIText scoregui;
	private float time;
	public static int score;
void Update (){
		time+=Time.deltaTime;
		//currentScore += (int)time;
		print ((int)time);
		score = (int)time * 100;
		//(int)time * 100 == score;
		scoregui.text = "Score: "+ score;
}
	}

Here is my script for the coins that should add 1000 points each:

using UnityEngine;
using System.Collections;

public class coins : MonoBehaviour {

	// Use this for initialization
	void OnTriggerEnter(Collider coll) {
			GameObject addScore = GameObject.Find("GUI");
			ScoreperSec scoreScript = addScore.GetComponent<ScoreperSec>();
		if (coll.gameObject.tag == "Player"){
			ScoreperSec.score += 100000;
			Destroy(this.gameObject);
		}
	}

}

Hi,

Got it working.Check below the scripts

using UnityEngine;
using System.Collections;
public class ScoreperSec : MonoBehaviour {
	public int startingScore = 0;
	public int currentScore = 0;
	public GUIText scoregui;
	private float time;
	public static int score;
	public static int localscore;
	void Update (){
		time+=Time.deltaTime;
		print ((int)time);
		localscore = (int)time * 100;
		score = localscore + coins.coinscore;
		Debug.Log ("total score "+score);

//		scoregui.text = "Score: "+ score;
	}
}

this is the coin one
using UnityEngine;
using System.Collections;

public class coins : MonoBehaviour {
	public static int coinscore;
	// Use this for initialization
	void OnTriggerEnter(Collider coll) {
		Debug.Log ("Trigger enter");
		if (coll.gameObject.tag == "Player"){
			coinscore += 1158;
			Debug.Log ("coins score"+ScoreperSec.score);
			Destroy(this.gameObject);
		}
	}
	
}

Hope it helps :slight_smile:

Coins script … Line 11

scoreScript.score += 100000;

Red