- Home /
Local Multiplayer Game | Input for player 2 completely broken.
Alright, I cannot for the life of me debug this glitch in my in-progress local multiplayer game. Player One's functionality is perfect. Player Two on the other hand, is lifeless and immobile. Upon adding the scripts in the UnitScript, the functionality from the previously functional CameraScript (For Player Two, not One) Any help on this would be greatly appreciated as I cannot seem to find the issue. Thanks!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraScript : MonoBehaviour {
public Transform Player1;
public Transform Player2;
bool Player1Placing;
bool Player2Placing;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
Player1Placing = GameObject.Find("GameManager").GetComponent<UnitScript>().Player1Placing;
Player2Placing = GameObject.Find("GameManager").GetComponent<UnitScript>().Player2Placing;
Player1.transform.rotation = Quaternion.Euler(Player1.transform.rotation.eulerAngles.x, Player1.transform.rotation.eulerAngles.y, 0f);
Player2.transform.rotation = Quaternion.Euler(Player2.transform.rotation.eulerAngles.x, Player2.transform.rotation.eulerAngles.y, 0f);
if (Player1Placing == true)
{
Player1.transform.rotation = Quaternion.Euler(45f, 0f, 0f);
}
if (Player2Placing == true)
{
Player2.transform.rotation = Quaternion.Euler(45f, 180f, 0f);
}
if (Player1Placing == false)
{
if (Input.GetAxis("1-Horizontal") >= 1)
{
Player1.transform.Rotate(0, 1, 0);
}
if (Input.GetAxis("1-Horizontal") <= -1)
{
Player1.transform.Rotate(0, -1, 0);
}
if (Input.GetAxis("1-Vertical") >= 1)
{
Player1.transform.Rotate(1, 0, 0);
}
if (Input.GetAxis("1-Vertical") <= -1)
{
Player1.transform.Rotate(-1, 0, 0);
}
}
if (Player2Placing == false) {
if (Input.GetAxis("2-Horizontal") >= 1)
{
Player2.transform.Rotate(0, 1, 0);
}
if (Input.GetAxis("2-Horizontal") <= -1)
{
Player2.transform.Rotate(0, -1, 0);
}
if (Input.GetAxis("2-Vertical") >= 1)
{
Player2.transform.Rotate(1, 0, 0);
}
if (Input.GetAxis("2-Vertical") <= -1)
{
Player2.transform.Rotate(-1, 0, 0);
}
}
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PointScript : MonoBehaviour {
public Text Player1PointsText;
public Text Player2PointsText;
public float Player1Points;
public float Player2Points;
// Use this for initialization
void Start () {
Player1Points = 2000f;
Player2Points = 2000f;
}
// Update is called once per frame
void Update () {
Player1PointsText.text = Player1Points.ToString();
Player2PointsText.text = Player2Points.ToString();
Player1Points += 1;
Player2Points += 1;
}
}
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class UnitScript : MonoBehaviour {
public bool Player1Placing;
public bool Player2Placing;
public Transform Player1Cursor;
public Transform Player2Cursor;
bool Player1A = false;
bool Player2A = false;
bool oh = true;
bool ov = true;
bool th = true;
bool tv = true;
float P1H;
float P2H;
float P1V;
float P2V;
Vector3 P1CP;
Vector3 P2CP;
// Use this for initialization
void Start() {
Player1Placing = false;
Player2Placing = false;
}
// Update is called once per frame
void Update() {
Vector3 P1CP = Player1Cursor.transform.position;
Vector3 P2CP = Player2Cursor.transform.position;
Player1A = Input.GetKey("joystick 1 button 0");
Player2A = Input.GetKey("joystick 2 button 0");
P1H = Input.GetAxis("1-Horizontal");
P1V = Input.GetAxis("1-Vertical");
P2H = Input.GetAxis("2-Horizontal");
P2V = Input.GetAxis("2-Vertical");
if (Player1A == true)
{
Player1Placing = true;
}
else
{
Player1Placing = false;
}
if (Player2A == true)
{
Player2Placing = true;
}
else
{
Player2Placing = false;
}
if (P1CP.x > 4.5f)
{
Player1Cursor.transform.Translate(-1, 0, 0);
}
if (P1CP.x < -4.5f)
{
Player1Cursor.transform.Translate(1, 0, 0);
}
if (P1CP.z > -0.5f)
{
Player1Cursor.transform.Translate(0,0,-1);
}
if (P1CP.z < -4.5f)
{
Player1Cursor.transform.Translate(0, 0, 1);
}
if (P2CP.x < -4.5f)
{
Player2Cursor.transform.Translate(-1, 0, 0);
}
if (P2CP.x > 4.5f)
{
Player2Cursor.transform.Translate(1, 0, 0);
}
if (P2CP.z < 0.5f)
{
Player2Cursor.transform.Translate(0, 0, -1);
}
if (P2CP.z > 4.5f)
{
Player2Cursor.transform.Translate(0, 0, 1);
}
if (Player1Placing == true) {
if (P1H >= 1f)
{
if (oh == true)
{
Player1Cursor.transform.Translate(1, 0, 0);
oh = false;
}
}
else if (P1H <= -1f)
{
if (oh == true)
{
Player1Cursor.transform.Translate(-1, 0, 0);
oh = false;
}
}
else
{
oh = true;
}
}
if (Player1Placing == true)
{
if (P1V >= 1f)
{
if (ov == true)
{
Player1Cursor.transform.Translate(0, 0, -1);
ov = false;
}
}
else if (P1V <= -1f)
{
if (ov == true)
{
Player1Cursor.transform.Translate(0, 0, 1);
ov = false;
}
}
else
{
ov = true;
}
}
if (Player2Placing == true)
{
if (P2H >= 1f)
{
if (th == true)
{
Player2Cursor.transform.Translate(1, 0, 0);
th = false;
}
}
else if (P2H <= -1f)
{
if (th == true)
{
Player2Cursor.transform.Translate(-1, 0, 0);
th = false;
}
}
else
{
th = true;
}
}
if (Player2Placing == true)
{
if (P2V >= 1f)
{
if (tv == true)
{
Player2Cursor.transform.Translate(0, 0, -1);
tv = false;
}
}
else if (P2V <= -1f)
{
if (tv == true)
{
Player2Cursor.transform.Translate(0, 0, 1);
tv = false;
}
}
else
{
tv = true;
}
}
}
}
Your answer
Follow this Question
Related Questions
how to create start the game automatically when all the players are joined using mirror networking? 0 Answers
How does one restart the scene in Unet Multiplayer without the player object respawning? 0 Answers
Multiplayer Respawning Problems 0 Answers