Why is the NetworkIdentity component making my Game Object invisible? (Unity) - unity3d

Currently trying to make a multiplayer snake game, I have never made a multiplayer game before. I am having a very strange issue where whenever I add the NetworkIdentity component to my 'Snake' game object, it becomes invisible, but is still there. The game is still functional; you just can't see the snake.
I have two pictures attached, one is the game with the NetworkIdentity component, one is the game without it. Thank you for the help.
Without component
With component

A) your image labels seem to be flipped .. exchange the Without and With ;)
and B) Afaik this is the expected behavior for any GameObject with a NetworkIdentity as long as you are not connected to any network yet. It will get enabled once you host or join a session.
You probably would rather convert this into the player prefab though and not have it in your scene from the beginning but rather let the NetworkManager automatically spawn it for every player in the session including yourself.

Related

The object I prefabs in Unity does not work

I'm making an online game with Photon in unity, everything is going well, but at the last moment I faced an unexpected problem.
I have a prefab object (tank) and I throw other prefab objects into this object, but it doesn't work, but it works when I put my object (tank) in the hierarchy as prefab and throw my other objects into my object (tank) as they are not prefabs.
For example, I want to make my game a mobile platform game, so I downloaded and added a joystick from unity asset store to my game.
If I assign this joystick to the movement script of my tank with the prefabs state, it does not work, but if I assign it to the movement script of my tank from the hierarchy part, it works.
What do you think is the reason for this, any ideas?
Edit, Instead of matching prefab objects from the inspector, joystick = GameObject.Find("Floating Joystick").GetComponent<FloatingJoystick>();` I matched it with my script file and it worked as I don't know why, but only the joystick in the hierarchy section worked, my fire button and camera tracking codes did not work. I think the reason is the connection I made with Photon, when connecting to photon, it is connected as server>loby>room, so the Start method works once until connecting to the room and it cannot find the specified object in the active scene. I have no idea how to solve this
sorry, my english is still bad so i use translate.
I think what you're saying is that you're assigning other prefabs to object slots in a script attached to your tank prefab.
If you do this when you're in prefab edit mode, then all your references to other prefabs are null when you instantiate the tank.
If you instantiate the tank in Edit mode, instantiate some other prefabs, and then make your assignments, then it works.
This is my understanding of your situation, at least. If this is right, the issue you're having with editing the prefab is that other objects are also prefabs, they're not instantiated.
You should be able to fix this by dragging the other prefabs onto your tank prefab, to instantiate them in the tank prefab, then drag those instantiated prefabs into your script slots.
As with basically everything in programming there are many other ways you can solve this, too, but this sounds the most like what you're looking for.

How to spawn an object only for a specific client using Unity Mirror?

NetworkServer.Spawn method spawns a gameobject, instantiated on server, to all clients. I have a canvas with UI for player. UI communicates with server through commands and RPCs. This canvas makes sense only to local player. There is no point in having these canvases instantiated on each player on client side. I`m trying to come up with a way to spawn one canvas for each player.
I`ve come across a suggestion to carry the canvas as disabled child object of player prefab and enable it with isLocalPlayer check. But I think that this solution is suboptimal for a type of game with loads of players.

Unity2D: Mirror Multiplying - How to view an opponent's screen in a match 3 game

I'm making my own match 3 multiplayer game, the concept is to have two people face off against each other person can face off another person by swapping tiles to make a line of the same form. I want to introduce multiplayer by connecting two players together and allowing each person to see their opponent's screen, as well as syncing their moves. So far, I have a simple match 3 game (I created one using different tutorials, mainly this playlist) and followed a simple multiplayer tutorial (Mirror) for a player to host or be a client. My problem is that I have no idea how to show both players their opponent's screen to each other. I even found an example of what I want the multiplayer mode in my game to be like. Can anyone point me in the right direction, please and thank you.
Additional information:
I'm using mirror for multiplayer
I created a network manager gameobject and added the necessary components to it. I also added the game pieces into the 'registered spawnable prefabs' and created an empty gameobject, called player for the player prefab.
Each game piece has a network transform and network identity component attached.
The player prefab object has a camera child under it to.
This is what I want my game to look like:
Overall, I want to have player's view each other's screen:
As you can see, both player's are connected, what I want to do it to allow each player see their opponent's screen. Does anyone have an idea on how I can do it?
Thank you! :)

Unity Photon Player Instantiation

I have a SteamVR Unity project which I'm converting to multiplayer.
When another client joins the game, instead of two different players seeing each other, each player has it's own version of the game where he controls all fo the player instances.
For example, while one player is connected everything is fine, but when a second player joins, the game just adds another Player prefab which the first player controls as well.
I tried replacing the Player with a simple cube and everything seems fine.
both the Player and the cube have Photon Transform View and Photon View scripts.
I would appreciate any help I can get.
This is a common problem, when you start with PUN. You probably setup a player prefab with network synchronization and instantiate that for each player. All scripts on the instances will act on the local input, which is what you see now.
You want two variants of the prefab, for local and remote representation. As it's impractical to always configure two prefabs, instead you build one which initializes itself (in Awake or Start) as local or remote. Your scripts should check the object's PhotonView if it's .isMine or not.
This can be done per Component (in each distinct script) or you could add a component which enables/disables the scripts on a GameObject, depending on isMine.
The Basics Tutorial does this, for example.
Unity doesn't know if it's multiplayer or not. When you give an input all of the scripts who are waiting for input takes it and behaves accordingly. To solve this basically create another player that doesn't take any input and spawn it for other players.

Player dies when hitting the floor

I am trying to make a game in unity, and I am new to unity and coding, and I have started making a game, I have made some progress on it but I am having trouble finding some of my answers on youtube and the unity forum, and sometimes when I do, I still can't get things to work. So this is what I'm trying to do.
I have a map and the player is on top of the tower, I want the player to fall and when hitting the ground, dies with it displaying game over, What could I do to make this happen and what script?
So i have this now,
// Ground.cs: Kills players that touch this.collider.
using UnityEngine;
// Attach this to the grass collider
public class Ground : MonoBehaviour {
// Called when another collider hits the grass.
// This is part of Unity!
void OnCollisionEnter(Collision c) {
// Does the other collider have the tag "Player"?
if (c.gameObject.tag == "Player") {
// Yes it does. Destroy the entire gameObject.
Destroy(c.gameObject);
}
}
}
Now, I need to it transition to a game over overlay, which asks me to restart, yes or no.
The resources are out there in regards to learning Unity3D efficiently.
Look at the Unity3D tutorials: https://unity3d.com/learn/tutorials
These tutorials are usually kept up to date in terms of not using deprecated code. Additionally, several of the tutorials will teach you how to set up events like those that you need.
In regards to your immediate question though, look into forming the logic for your game.
You're going to need allow your player gameobject to fall via either gravitational force enacted on a rigidbody or hard-coded physics being applied to the gameobject. Next you will need to determine if the player gameobject has collided with the "floor". If so you will need to trigger an event to destroy the player gameobject, then display a GUI Text that says Game Over.
Look around more at tutorials and get better acquianted with Unity. Over time, you'll learn how to make things happen. If you have more questions, feel free to ask.
Answer to you update:
If your code is functioning correctly and your destroying your gameobject correctly, then awesome! You're learning fast!
The next step could be:
Create a Canvas, create a gui panel, create a gui text
That gui text object can have your Game Over Text
Now, create a button that you will utilize as the restart button
You can have the button call a function which utilizes SceneManager.LoadScene to reload the scene. Look here for an example: http://answers.unity3d.com/questions/1109497/unity-53-how-to-load-current-level.html
Next, Disable the panel as you will not need it until your player dies.
When your player collides with the ground you will destroy the player gameobject and set the panel you created to active. (you can trigger these actions via a listener in code or via the button component in the inspector).