Home>

I am making a 2D side-scrolling action game with Unity.
When I tried to press Play to start the game, only the player character was not displayed on the screen.

I investigated and tried various things myself, but I could not solve it because I was a beginner and I did not understand it well.
Even if you don't get an answer, I would like to have other things to try and advice. Thank you.

The player character is displayed in the Scene view, Game view, and the camera preview of the Main Camera, but when the game is started in Play, it disappears from the screen and disappears.
However, the script applied to the player is functioning, and it is in the "state where you can control invisible characters".

All the other enemy characters, the ground, the background, etc. are always displayed, and the scripts applied to them including the player are all working properly.
When I launch the game, I get no error message.


  

What I tried

Main Camera
I made the child object of the player independent, and applied a script that follows the player.
(Postscript) Originally, only the image disappeared while the script was running when the objects other than the player such as the enemy, the ground, and the background were able to operate the player in the empty space. I messed up somewhere (other than the script) to fix it, and now only the player's image disappears.

The script is working properly, and it seems that the invisible player follows the movement according to the movement.
Confirmed that Culling Mask is Everything.
↓ Script
  

Canvas
Created to display the result screen for elapsed time and goals.
There is no change whether Render Mode is Screen Space-Overlay or Camera.

Supplemental information (FW/tool version, etc.)

Version is Unity 2019.2.15f1 (64-bit)

The platform in Build Settings is for iOS.

Referenced site
Le @ DKRevel "How to make a game"
https://dkrevel.com/makegame-beginner

Addendum
↓ Script applied to the player







  

Also, the image below is the state of the Inspector view when Player is selected in the Hierarchy view while the game is moving in Play.




  

↓ Game manager script (GManager)
  

↓ Stage controller script (StageCtrl)
  

Please give us your answers and advice.

  • Answer # 1

    Sorry for the lack of explanation ...! Only the Inspector said that "I would like to give you a screenshot", the script is as the sentence in the question sentence ... I wish I could copy and paste the script so that it replaces the part written as "code" in the template that is inserted when the button with the "" icon is pressed. I'm sorry to bother you ...
    However, it seems to be a long script, so if you paste it in the question sentence, you may have hit the character limit this time. For the time being, I think it's OK to leave the screenshot as it is.

    Suspected as a direct cause of the player not being visible during gameplay, it seems like the context of the camera and the player is out of order
    In the camera script ...

    transform.position = new Vector3 (PlayerPos.x, 0, -10);

    For example, there are places where the X coordinate is made to follow the player, but the Z coordinate is fixed at -10. Therefore, it seems that the Z coordinate of the camera being played will always keep the position of -10.

    On the other hand, in the screenshot you presented

      

    The Z-coordinate of the player shown in -shows -4993.0, which seems to have jumped to the front abnormally. Since the Z coordinate of the camera is -10, I imagine that the player is behind the camera and far away, and I don't think it's reflected in the camera.

    I'm sorry, but I'm still not sure why this happened. Before the game starts, the players are properly reflected in the Camera Preview and Game view, so at this point I think that the context is normal.

    What is the positional relationship of each object in the Z direction before the game starts? Is the position of the player, camera, and other objects such as continue position objects normal?

    If they are not suspicious, next time you run the game and observe the Z coordinate of each object, you may get further clues. I wonder if there are any unusual movements such as the player flying in the -Z direction ... (I think that it is unlikely as long as you see the script presented, but anyway it is a clue Is where I want to find).

    As shown in the figure below, switching the "2D" button in the Scene view and observing the scene from an angle, or playing the game with the Scene view and Game view side by side at the same time may be useful for finding anomalies. not.