Mouse cursor is invisible in unity -


i's designing first person shooting game in unity. used fps controller control player. hence, mouse cursor remains invisible of time , when press escape, becomes visible. but, problem when load new scene scene uses fps controller, mouse cursor remains invisible although new scene not use fps controller. moreover, pressing escape not show mouse cursor in new scene.

you can deal in few ways, here core of problem: changing cursor.visible field not scene dependent, , not reset when new scene loaded. because of that, need set cursor.visible = true; on level load.

i suggest making simple script cursorvisibility read this:

public class cursorvisibility : monobehaviour {     void onlevelwasloaded(int level)     {         if (findobjectoftype<firstpersoncontroller>() != null)         {             cursor.visible = false;         }         else         {             cursor.visible = true;         }     } } 

place on empty game object in every scene , have cursor visibility handled automatically.

you can place function:

void onlevelwasloaded(int level) {     if (findobjectoftype<firstpersoncontroller>() != null)     {         cursor.visible = false;     }     else     {         cursor.visible = true;     } } 

in other script unique scene without first person controller.

just make sure replace name of script whatever fps controller named :)


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -