- Home /
Question by
mexey · Apr 05, 2014 at 03:30 PM ·
c#instantiatenullreferenceexception
Instantinate NullReferenceError problem
Hi all. Can anybode tell me whats wrong with this code?
MonsterObject = Instantiate (Monster1prefab, pos, Quaternion.identity) as GameObject;
EnemyAI_Hunter ai = MonsterObject.GetComponent<EnemyAI_Hunter>();
ai.player = GameObject.Find("PLAYER").transform;
debugObject = Instantiate (infotext, pos, Quaternion.identity) as GameObject;
TextFollow tf = debugObject.GetComponent<TextFollow>();
tf.Target = MonsterObject.transform;
Code is accepted by compiler. First 5 strings work fine, last one issues a error everytime:
"NullReferenceException: Object reference not set to an instance of an object"
Comment
Your answer
Follow this Question
Related Questions
AddForce NullReferenceException 1 Answer
Attach script twice. 1 Answer
Distribute terrain in zones 3 Answers
NullReferenceException and m_InstanceID == 0 on LoadLevel (C#) 1 Answer
Multiple Cars not working 1 Answer