public Transform prefab;
GameObject target;
void Start () {
teksture = Instantiate(prefab, new Vector2(transform.position.x, transform.position.y), Quaternion.identity)as GameObject;
}
void Update () {
teksture.transform.position = transform.position;
}
“NullRefrenceExeption: Object reference not set to an instance of an object”
What am I doing wrong? The project is in 2D. The script doesn’t notice it out side of Start function.
EDIT: I added prefab I just drag and drop the prefab into place in unity. And also now I noticed that if I instantiate teksture in update function and try to call it in any way, it gives the same error. Also I should say that it does spawn it.
You've only given us part of the script and don't give us info about the error. How is 'prefab' declared? How is 'prefab' initialized? How is 'teksture' declared? If you put a 'Debug.Log(teksture)' just below line 4, does it show a null value or is it being initialzied?
– robertbuHave you declared teksture anywhere in your code.?
– Theinsanekiller