- Home /
How can I get "!networkView.isMine" to function properly?
Hello,
I am working on a multiplayer game that is being created within a network. So far, everything is working fairly well... Except my networkView. When I open to instances of the game (one in the editor and one in the player), it seems as though the game is wanting to duplicate the player and camera, causing one screen to control the player from the other, and vice versa.
MovementScript.js Code:
var speed:int;
var rotateSpeed:int;
var gravity:int;
private var cc:CharacterController;
function Start(){
cc = GetComponent(CharacterController);
}
function Update(){
if(networkView.isMine)
{
//INITIATE AND MAINTAIN GRAVITY
cc.Move(Vector3(0, -gravity, 0));
//MOVE FORWARD
if(Input.GetKey(KeyCode.UpArrow))
{
cc.transform.Translate(Vector3(0, 0, 1) * speed * Time.deltaTime);
}
//MOVE BACKWARD
if(Input.GetKey(KeyCode.DownArrow))
{
cc.transform.Translate(Vector3(0, 0, -1) * speed * Time.deltaTime);
}
//ROTATE RIGHT
if(Input.GetKey(KeyCode.RightArrow))
{
cc.transform.Rotate(Vector3(0, 1, 0) * rotateSpeed);
}
//ROTATE LEFT
if(Input.GetKey(KeyCode.LeftArrow))
{
cc.transform.Rotate(Vector3(0, -1, 0) * rotateSpeed);
}
}else{
enabled = false;
}
}
Does anyone know where I might be going wrong?...
How you instantiate the player? With Instantiate(), or with Network.Instantiate()? You have to verify the owner of NetworkView to be different in both instances.
I'm sorry. I'm fairly new to the Unity thing, so I don't quite understand what you mean...
You have to read a bit more the tutorials about how the networking it's working on Unity. Networking is not an easy thing and there are more ways to create and control objects from a machine/unity instance to other. The idea is the object having attached NetworkView have an owner. The owner is the creator of object, aka Unity instance (editor,player) which create (instantiate) the object from the project on the scene. If use Network.Instantiate, the owner is Unity instance sending call to other Unity instances to create object. If use Instantiate and use RPC to other Unity instances to create the object, than each Unity instance will create the object in local scene, so each Unity instance will be the owner, we having more owners. 'is$$anonymous$$ine?' mean 'I am owner?' so that game logic have to take care about who created the object. It's a good idea not to drag an object on the scene expecting it just to be easy controlled over network, but use instantiation ins$$anonymous$$d, cloning objects from project hierarchy. Look on your code for 'Instantiate'. I hope this give you a direction.
I have instantiated the object. A cloned object is created when I join the server as a client. I also use the "networkView.is$$anonymous$$ine" code in my $$anonymous$$ovementScript.js. I'm not sure why my code is not functioning properly.
Answer by CJay7 · Jan 13, 2014 at 06:59 AM
I have solved the problem with my network. I will try to remember to post my solution tomorrow.
What was your solution :) ,I know this is an old thread but might help me/others..