- Home /
Script Errors with Unity 3.0
This static function now gives in an error in Unity 3.0, but worked in Unity 2.6:
static function map(v1, a1, b1, x1, y1) {
// returns a value that has the same relation to x and y as the value v has to a and b
return (v1 == a1) ? x1 : (v1 - a1) * (y1 - x1) / (b1 - a1) + x1;
}
The error is as follows:
NullReferenceException: Object reference not set to an instance of an object
Boo.Lang.Runtime.RuntimeServices.InvokeBinaryOperator (System.String operatorName, System.Object lhs, System.Object rhs)
Functions.map (System.Object v1, System.Object a1, System.Object b1, System.Object x1, System.Object y1) (at Assets/Scripts/Functions.js:66)
Gauge.setVal (System.Object inputVal) (at Assets/Scripts/Instrument Panel/Gauge.js:37)
Instrument Panel Script.Update () (at Assets/Scripts/Instrument Panel/Instrument Panel Script.js:76)
In addition, this gave an error:
helicopterScript = helicopterGameObject.GetComponent( "Helicopter_Script" );
helicoperRigidBody = helicopterScript.rigidbody;
Is there a different way now to reference a property in another object's script?
The second script doesn't really make sense. You're getting a script component and then trying to access a rigidbody by referencing a script from a GO.
Reference the GO ins$$anonymous$$d through whatever method and call helicopterGO.rigidbody .
What you say makes sense, however, early on I found this example in the docs that was setting properties via the script:
transform.Find("Hand").GetComponent(OtherScript).foo = 2;
Yes, that's perfectly viable. But rigidbody is parented to the GO not to the script. so you should do something like:
var handObject = gameObject.Find("Hand") as gameObject; var handRigidBody = handObject.rigidBody;
Your answer
Follow this Question
Related Questions
Can I run static var from another script ؟؟؟ 2 Answers
Unknown identifier, OnCollisionEnter Error 1 Answer
Global Varible Problem 2 Answers
"transform" in a static function 1 Answer