0
\$\begingroup\$

I am trying to transform the position of an object. I have totally 3 Objects and 2 triggers, objects are 1. Left_Wall, 2. Right_Wall, 3. Obstacles. 1st trigger for transform the position of an objects y = -50, 2nd trigger for transform the position of an objects y = -7. Left wall and Right Wall are placed inside the environment. the environment will instantiate automatically for looping. if the player crossed the first environment previous environment will delete automatically. at that time in second clone environment if the player triggered means it will display a message as

MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it. Your script should either check if it is null or you should not destroy the object.

In first Clone environment its working perfectly. second clone environment its not working.

enter image description here

enter image description here

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Please please please use Code Blocks to paste your code instead of screenshots.

Now you say that

the environment will instantiate automatically for looping

And your variables sideLft and sideRit are null when you need them. So why not perform the search of the scene just before you do your action? Take your code from Start function and move it in the beginning your OnTriggerEnter. I would provide a code block for you if I could copy some from your question.

\$\endgroup\$
2
  • \$\begingroup\$ yes, I also did the same. now the problem is i want to change and reset only y position . if i gives sideLft.transform.position = new vectro3 (0,-50,0); Means the game object x position is moving to 0. \$\endgroup\$ Commented Dec 11, 2015 at 9:30
  • \$\begingroup\$ then you can do: Vector3 pos = sideLft.transform.position; pos.y = -50f; sideLft.transform.position = pos; \$\endgroup\$ Commented Dec 11, 2015 at 9:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .