I’m trying to turn a pinball game into a multiplayer game with UNet. My flippers are giving me a bit of a trouble. I want both players to be able to control the flippers. I’m using a hingejoint2d to move the flippers. The flippers are a child of the hingejoint. Here is the setup
Here is my simple script. It works well for single person but can’t seem to figure out how to get it to work multiplayer
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class LeftBottomFlipper : NetworkBehaviour {
public float speed = 1000f;
public JointMotor2D motor2D;
public HingeJoint2D myHingeJoint;
// Use this for initialization
void Start () {
myHingeJoint = GetComponent<HingeJoint2D>();
motor2D = myHingeJoint.motor;
}
private void Update()
{
if (Input.GetKey(KeyCode.A))
{
FlipperUp();
}
else
{
FlipperDown();
}
}
private void FlipperUp()
{
// set motor speed to max
motor2D.motorSpeed = speed;
myHingeJoint.motor = motor2D;
}
private void FlipperDown()
{
// reduce motor speed
motor2D.motorSpeed = -speed;
myHingeJoint.motor = motor2D;
}
}
Any help is greatly appreciated. Thanks!