Accessing another game objects script component.

Hi there,
I have read a bunch of posts about this but I guess I need a little clarity.

First question: is it a bad idea to have spaces in script names (ie… script player.js)

I feel that perhaps this is obstructing me from accessing the components of that script.

I’ve used this before

var enemyScript = hit.transform.GetComponent(cubebehavior);
enemyScript.numberOfClicks -= 1;

with quite a bit of success but this was utilizing a raycast to grab the target object plus my script name was all one word, in this next case I just want to access another script in a more abstract fashion, like this:

// Inspector variable
var p :Transform;
if(hit.gameObject.tag == "bullet"){
var pScript = p.transform.GetComponent("script player");
pScript.playerScore += 10;

Now, with this new method I can’t seem to get component access (specifically variable access)… Is this because I’m using a transform rather than a game object, because I’ve got spaces in my script name and therefor have to search for a string or am I just doing this all wrong.

Thanks in advance!

AFAIK, you can’t have spaces in class names. For UnityScript, it generates the class name automatically based on the file name, but I’m not sure what it converts spaces into. Underscores, maybe? I would recommend not having spaces in the script name at all though.

do not use spaces… if you want to separate words in the name two common practices are underscores, and camel notation.

underscores: hello_world
camel: HelloWorld

Thanks for the info. Otherwise does it look like those examples are sound and workable?

sure, just get rid of the spaces