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