- Home /
Score not adding!
Help I want to add 1 point to my other .js script but it doesn't work. Here's my code. Gotoquiz1 is the name of my script a.
Script A:
static var score : int = 0 ;
function Start()
{
print("Score: 0");
}
function Update()
{
print("Score: "+ score);
}
Script B:
function OnMouseUp()
{
gotoquiz1.score += 1;
}
Is 'Script A' and/or 'Script B' attached to any gameobjects ?
Do you get an error? Where are Script A/B? $$anonymous$$ore info is needed
Answer by DeBunked · Feb 20, 2013 at 10:53 PM
You probably have to define the gotoquiz1 object as a script before it can associate the right property (score in your case) with it. Try adding this to script B and assigning script A to it in the inspector:
var gotoquiz1 : Script;
Answer by DaveA · Feb 20, 2013 at 11:05 PM
Make sure you have the other script available.
var gotoquiz1 : Gotoquiz1; // you said that's your script, right? Gotoquiz1.js?
Now assign that with the Inspector by dragging the object containing Gotoquiz1.js onto that exposed variable.
Or,
function Start()
{
gotoquiz1 = GetComponent.<Gotoquiz1>(); // if the script is on the same object
OR
gotoquiz1 = GameObject.Find("otherobject").GetComponent.<Gotoquiz1>(); // if the script is on the 'other object'
}
Your answer

Follow this Question
Related Questions
Adding lights and cameras to scenes with cSharp script 2 Answers
Add on to Script 1 Answer
Move from point A to point B, then destroy? ( java S) 2 Answers
add close button to script 1 Answer