-2

I know there are a few answers on that question, but they don't work for me or I am only to stupid. Sorry.

Here are my scripts:

menu_options.js - http://pastebin.com/NFXD3ZgP

Transmitter.js - http://pastebin.com/kCmGTgbH

i've attached the Transmitter.js to a specific object. It's called "_Transmitter".

If I run my scripts I get following Error:

Assets/Script/menu_options.js(7,40): BCE0023: No appropriate version of 'UnityEngine.GameObject.GetComponent' for the argument list '(UnityEngine.GameObject)' was found.

Why? And what does it mean?

What did I understand wrong in the tutorials and answers?

I also tried this:

trans = Transmitter.gameObject.GetComponent(Transmitter);

and this:

trans = Transmitter.GetComponent(Transmitter);
Steffen Moritz
  • 7,277
  • 11
  • 36
  • 55
  • I Get it! PlayerPrefs.SetInt("light", 50); and PlayerPrefs.GetInt("light"); i am using now! –  Jan 15 '15 at 20:11
  • 1
    `PlayerPrefs` is overkill when all you want to do is pass a parameter between scripts. Check my answer below. – apxcode Jan 15 '15 at 20:16

2 Answers2

1

To pass a parameter to another script you must first have a reference to that script.

ScriptA

function Start()
{
    var reference : GameObject = GameObject.Find("Name Of GameObject").GetComponent("ScriptB");

    reference.setValue(50);
}

So we Find() the GameObject that has the script, we first need the name of the GameObject that has it. Then we use GetComponent() to grab the script's reference. Then we make the function call to set a parameter.


ScriptB

private var myValue : int;

function setValue(var amount : int)
{
    myValue = amount;
}
apxcode
  • 7,696
  • 7
  • 30
  • 41
0
PlayerPrefs.SetInt("variablenname", 1);

and

var v1 = PlayerPrefs.GetInt("variablenname");

works great!

Bart
  • 19,692
  • 7
  • 68
  • 77
  • Please make sure to keep your posts in English. The site is English only and looking at your questions you speak it just fine. ;) – Bart Feb 07 '15 at 21:39