Hello,
So I am trying to increment the score in one of my scrips when the person hits a coin. I think I may be linking my scripts wrong as I have been getting this error all night. I have tried a ton of different methods and have no idea. The tricky part being that the PlayerInfo script is on the player while the CoinOnCollision script is on the coin. any ideas?
PlayerInfo script
#pragma strict
var currentHealth : int = 10;
var maxHealth : int = 10;
public var currentScore : int = 0;
function RaiseScore(score : int) {
this.currentScore += score;
}
function Update () {
}
CoinOnCollision script
#pragma strict
var playerInfoScript : PlayerInfo;
function Start() {
playerInfoScript = GameObject.FindGameObjectWithTag("Player").GetComponent("playerInfoScript");
}
function OnTriggerEnter() {
playerInfoScript.currentScore += 10;
Destroy(gameObject);
}
Can you paste in the error messages please?
– SpinnernicholasLine 3 and line 6. The variable is of type PlayerInfo, the GetComponent method is passed a string "playerInfoScript". This is the error.
– fafasethe error I'm getting is NullReferenceException: Object reference not set to an instance of an object CoinOnCollision.OnTriggerEnter () (at Assets/Standard Assets/Character Controllers/Sources/Scripts/CoinOnCollision.js:9)
– Majinsarek