hi, i have some problem, i am new in JS, and other scripting languages, i have problem: 1. i have script: script1.js, on this scrip i have function: Code (csharp): function Update() { if (minitab.minitab == false) { script2.skaluj(0.5202637, 0.142, 1, 0.01); } if (minitab.minitab == true) { script2.skaluj(0.5202637, 0.1259766, 1, 0.04); } } this function reffer to function on script2 2. on script2 i have: Code (csharp): static function skaluj(x : int, y : int, z : int, sy : int) { object.transform.localScale.y = sy; object.transform.position = Vector3 (x, y, z); } 3. and i have error: Code (csharp): NullReferenceException: Object reference not set to an instance of an object script2.skaluj (Int32 x, Int32 y, Int32 z, Int32 sy) (at Assets\skrypty\script2.js:34) pelenekran.Update () (at Assets\skrypty\przyciski\menu\pelenekran.js:42) 4. script1 is attachet to GUITexture, i like to transform this texture by script2 called by script1. who can help me?? plese and thank. :]
What is "object" referring to in script2.js? I assume it's supposed to refer to the original game object (your GUITexture), if so then you need to pass a reference to that object when calling the function. For example: Code (csharp): // script1 function Update() { if (minitab.minitab == false) { script2.skaluj(gameObject, 0.5202637, 0.142, 1, 0.01); } if (minitab.minitab == true) { script2.skaluj(gameObject, 0.5202637, 0.1259766, 1, 0.04); } } Code (csharp): // script2 static function skaluj(object : GameObject, x : int, y : int, z : int, sy : int) { object.transform.localScale.y = sy; object.transform.position = Vector3 (x, y, z); } As your code was provided there is no valid reference assigned to the variable 'object' in script2.js and thus the error. Give that a go and see how it works!
i dont know what i done bad (maybe this is problem of time 2p.m) but this dont work... no exacly dont work, but now my GUITexture disapeard :/ i dont have any errors... i was copy Code (csharp): object : GameObject and Code (csharp): gameObject into my code... if i done somthing bad please tell me. i will be back at the morrning
While you might think your animation values are "sensible", are they really sensible? Your GUITexture may be disappearing as it's animating, quickly, right out of view. Select the GUITexture object in the hierarchy and hit play, watch the values. Does it animate the numbers? If so then things are "working" and you need to adjust the amounts used (likely with much smaller values).
hmmm... i dont know. this is somthink like: gameObject doesent, sent to script name of this gameobjects, only string: gameObject. no, this is not this problem. because values are not change. i dont know maybe is another way to have name of GUITexture, who call a function???
A few thoughts, some of which I should have mentioned before: - Don't set the localScale for the GUITexture's game object, if you want to resize it then adjust the pixel inset rect value instead. - When you call skaluj() you provide floats, yet in that function you specify them as int's, you might want to clarify which you hope to use. - Commenting out the scale line and the if conditional in script1 makes your scripts work, as they are, with no issues. When I press play the GUITexture object jumps to the specified position (0.5202637,0.142). Nothing disappears for me, so I'm wondering if that is a complication due to your scaling attempts via localScale. Please test this in a bare bones simple new project (one just to sort this out). I sense that there are other factors at play given the line numbers cited in your initial report above (error on line 32 of script2, yet there are nowhere near 32 lines shown here ). This code works in general though, just trim out the localScale setting and your float/int type declarations and I think you should have it sorted.
ok, i will try :] thanks very much :] and i will write heare other questions or sumary, what helps me :] --- o my good, i am so stupid, and blind you have right, using float when i declare int, are wery sdtupid... but more stupis is using int, where i must us float :] when i change inf to float, everything start to by ok. thanks very much :]