- Home /
Object Reference Not Set to an Instance of an object
Keep getting this error in line.SetPosition(1, bob.transform.position); can someone help me fix this? this code is just to draw a grappling hook line from the shooter to a designated distance.
// Line start width
var startWidth = 0.05;
// Line end width
var endWidth = 0.05;
//or you could use...
//var aMaterial : Material;
// get line going...
private var line : LineRenderer;
function Start ()
{
line = this.gameObject.AddComponent(LineRenderer);
line.SetWidth(startWidth, endWidth);
line.SetVertexCount(2);
line.material.color = Color.black;
//we need to see the line...
line.renderer.enabled = true;
}
function Update ()
{
//get the shooter object...
bob = GameObject.Find("Shooter");
//set starting point of line to this object, in this case the grappling hook prefab
line.SetPosition(0, this.gameObject.transform.position);
//set the ending point of the line to the shooter object
line.SetPosition(1, bob.transform.position);
}
Comment
Are you sure that 'Shooter' always exists in the scene and that the name 'Shooter' is exactly the name of the game object? For example 'Shooter' is not 'shooter'.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Object reference not set to an instance of an object 1 Answer
Object Reference not set to an Instance 2 Answers
NullReferenceException:"Object reference not set to an instance object" 1 Answer
i don't understand "NullReferenceException: Object reference not set to an instance of an objec" 0 Answers