- Home /
Another Null Reference Exception
I am getting a null reference to the class partHull in the following code: (this is not all of it, only the important parts)
public class partHull extends UnityEngine.MonoBehaviour
{
public var position :int;
public var isPartUsed :boolean = false;
private var jaska :GameObject = Resources.Load("Alus");
private var partLoc :Vector3;
public function partHull(num : int, vector : Vector3)
{
position = num;
partLoc = vector;
}
public function guiLoop()
{
if (GUI.Button(Rect(10,170,50,30),"Plus")) {
if (!isPartUsed) {
partHullInstance = Instantiate(jaska, partLoc, transform.rotation);
isPartUsed = true;
partHullInstance.AddComponent("FixedJoint");
partHullInstance.GetComponent("FixedJoint").connectedBody = rigidbody;
partHullInstance.GetComponent("FixedJoint").breakForce = 5;
partHullInstance.GetComponent("FixedJoint").breakTorque = 5;
} else {
Destroy(partHullInstance);
isPartUsed = false;
} } } }
paikka = new Vector3(-3,-3,0.75);
var hull = gameObject.GetComponent(partHull);
hull.partHull(1,paikka);
function OnGUI () {
hull.guiLoop();
}
The line giving me problems is hull.guiLoop(); It should be noted that hull is successfully referenced once in hull.partHull(1,paikka);
I have no idea what is wrong, and I am new to js so help is appreciated.
Answer by DaveA · Aug 15, 2013 at 12:04 AM
Lines 28-30 are not in any function. 28 and 29 should be moved to line7, and 30 should be in some function.
I put 28 and 29 in start, because they initialize partHull hull.
I moved 30 to start also.
But now it tells me 'hull' is undefined.
Please tell me why it does not recognize my object
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to make a selection system? 1 Answer
How to spawn objects in a specific range of random location 1 Answer
Why is my code not working? 1 Answer