script works in editor but not in exported players

Hi people,

I can’t get why some very simple scripts work in Unity’s editor and not in exported players (standalone and web).

Here’s the stuff
No issue with draging objects script. But as mentionned, the user should be able to move the camera :

  • orbital around the objects
  • up and down (with a “Look at” script so that camera always points on the chair)

To do this I used :
1/ a first null object (say “null_1”) at the middle of the scene
2/ a second (“null_2”), parented to the first one and translated few meters away
3/ The camera parented to “null_2” (distance 0)

Now scripts attached :

To null 1 :

var RotateSpeed = 2.0;

function Update () {
	
		var h = RotateSpeed * Input.GetAxis ("Horizontal");
		transform.Rotate (0, h, 0);

	}

To null 2 :

var verticalSpeed = 2.0;

function Update () {

		var v = verticalSpeed * Input.GetAxis ("Vertical");
		transform.Translate (0, v, 0);
	}

To camera :

var target : Transform;

function LateUpdate () {
			// Just lookat
		    transform.LookAt(target);
}

(where target is null 1)

“Vertical” and “Horizontal” are setted as arrow keys in the input panel.

It works perfectly in Unity’s editor. Not in players.

What’s wrong ?

What is curious is that I used almost the same scripts for a similar camera nav in another project.
HERE

In this second scene the scripts are a bit different because I need some horizontal translation for my “null_1”

Thus they are setted as follows :

null 1 :

var RotateSpeed = 2.0;
var TranslateSpeed = 2.0;


function Update () {
	
		var h = RotateSpeed * Input.GetAxis ("Horizontal");
		transform.Rotate (0, h, 0);

	// ADDED
		var v = TranslateSpeed * Input.GetAxis ("Vertical");
		transform.Translate (0, 0, v);

	}

null 2

var verticalSpeed = 2.0;

function Update () {

	// ADDED
		var v = verticalSpeed * Input.GetAxis ("Jump2");
		transform.Translate (0, v, 0);
	}

(“Jump2” = R and F keys)

camera > “look at” script

And it works…

By the way there are no difference in input preferences settings from the first scene to the second one… they both are stored in the same Unity Project anyway.

Any help ?

no answer… :cry:

anyone please ?

I got new similar issue in the scene with “buttons” and this code (attached to some Gui textures) :

var mat1 : Material;
var obj1 : GameObject;
var obj2 : GameObject;


function OnMouseDown () {
obj1.renderer.material = mat1;
obj2.renderer.material = mat1;

}

This code is supposed to change the color of objects (chairs) by clicking on “buttons”.

Again, it works fine in editor. Not in standalones.

You should check the build log to see if any errors occurred during the build. You can do this straight after a build by opening the console window and clicking the Open Editor Log button in the top right corner.

Input settings are per project, not per scene.

As for “perfectly” — check your console.

Thanx for replies.

I know that (see end of my first message) and that’s precisely why I don’t see in what way Input settings may be involved as in one scene everything works correctly while it does not in another one, with scripts that are very similar.

andeeee,

I checked the build log as you adviced and nothing seems to appear wrong except, maybe, two things :

1/ a “warning” mentionned not at the building of the projector but at the opening of the scene (ie : launching of Unity).

Initialize mono
2010-09-16 20:17:55.237 Unity[167:20b] NSDocumentController Info.plist warning: The values of CFBundleTypeRole entries must be ‘Editor’, ‘Viewer’, ‘None’, or ‘Shell’.

(but this seems to appear at each launching of Unity whatever scene is so I don’t think it’s involved in my current issue)

2/ Building projector log part seems OK though I noticed it mentions as “used” some scripts that are NOT used at all in the scene - but are stored in the same Project.

Also I got errors not in “editor log” but in “player log” :

Thread was not cleaned up!
ference not set to an instance of an object
itemClicked.OnMouseEnter ()
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UnityEngine.MouseOverPair:SendMessage(String)
UnityEngine.SendMouseEvents:smile:oSendMouseEvents()

(Filename: Line: -1)
NullReferenceException: Object reference not set to an instance of an object
itemClicked.OnMouseExit ()
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UnityEngine.GameObject:SendMessage(String, Object, SendMessageOptions)
UnityEngine.MouseOverPair:SendMessage(String)
UnityEngine.SendMouseEvents:smile:oSendMouseEvents()

(Filename: Line: -1)
Thread was not cleaned up!

What I don’t understand is :

  • what does this mean ?
  • why these errors are mentionned about the player (while the player’s editor seems to work) and not in the building (that… does not work).