- Home /
Pickup Counter script
I have this script on my pickup ( a banana )
var targetObj : GameObject;
function OnTriggerEnter()
{
var bananacount = targetObj.GetComponent(bananacount);
bananacount.money++;
audio.Play();
Destroy(gameObject);
}
and this on my main char.
var moneydisp : GUIText; var money : int;
function Update () {
moneydisp.text = "Bananas : " + money;
}
It's supposed to add one to the counter every time the trigger is entered, but in the banana script it won't let me add to the score using money++ or money = money + 1 at all, and i get an error of 'Expression Cannot be assigned to'. How can i get this to work 'right'?
Answer by Adam Rademacher · Oct 03, 2010 at 10:07 PM
Try making money static.
static var money: int;
With this, you don't need to call a GetComponent(bananacount), just
bananacount.money++;
won't work, i get "unknown identifier 'bananacount'" and the same ' Expression cannot be assigned to' error.
dw worry, i'd written banacount ins$$anonymous$$d of bananacount.
Your answer
Follow this Question
Related Questions
pickup counter and timer help 0 Answers
Problem assigning transform variable to prefab. 1 Answer
Character Counter using GUILayout.Label 1 Answer
Pickup Counter Script 2 Answers
Unity JS - Picking up objects 1 Answer