- Home /
Access vars from other js scripts
Hi, I have two scrips(js). One with a simple score keeper and another(we will call it enemy script) that has a few functions(one is die). What I have been trying to do is on the simple score keeper script is detect when the enemy script uses the function die. Thats it. I am a beginner and a little confused. So basically what I need to do is have one script be able to tell when another script is doing something. Thanks for your time. I have been looking up syntax like get component and such but I am having trouble figuring this out. Here is my score keeper script:
var MyScore : float = 0;
function Update ()
{
guiText.text = "Score : " + MyScore;
}
Answer by NoseKills · Feb 27, 2015 at 11:43 PM
You can't "detect when another script is using function". What you do is call funtion B from function A to let B know A was called. Or more accurately "do B when A happens"
So call "addScore()" from your "die()" function. How to call functions in other scripts has been covered plenty of times here.
Your answer
![](https://koobas.hobune.stream/wayback/20220613184538im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to email highscore through android? 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Keeping track of items 1 Answer