Look, I want to make a puzzle-like game and I need to be able to play with 2 different characters. I mean, for example, 1 player must be in a pressure plate and the other in another place so you have to move each one separately. That’s what I have right now, but I have no idea of how should I do it. I mean, my scripts does not control the second player or, depending on what I change, it controls both…
Any help is apreciatted.
Here’s the script.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FifthSoulsMovController : MonoBehaviour {
//CAMARA
public Camera FPSCamera;
public Camera FPSCamera2;
public float horizontalSpeed;
public float verticalSpeed;
float h;
float v;
//MOVIMIENTO
public float run = 1;
public int forceConst = 4;
private bool canJump;
private Rigidbody selfRigidbody;
// Use this for initialization
void Start () {
//CAMARA
FPSCamera.enabled = true;
FPSCamera2.enabled = false;
//MOVIMIENTO
selfRigidbody = GetComponent<Rigidbody> ();
}
void FixedUpdate (){
if (canJump) {
canJump = false;
selfRigidbody.AddForce (0, forceConst, 0, ForceMode.Impulse);
}
}
// Update is called once per frame
void Update () {
//CAMARA
if (FPSCamera.enabled) {
h = horizontalSpeed * Input.GetAxis ("Mouse X");
v = verticalSpeed * Input.GetAxis ("Mouse Y");
transform.Rotate (0, h, 0);
FPSCamera.transform.Rotate (-v, 0, 0);
}
if (FPSCamera2.enabled) {
h = horizontalSpeed * Input.GetAxis ("Mouse X");
v = verticalSpeed * Input.GetAxis ("Mouse Y");
transform.Rotate (0, h, 0);
FPSCamera.transform.Rotate (-v, 0, 0);
}
if (Input.GetKeyDown (KeyCode.G)) {
FPSCamera.enabled = !FPSCamera.enabled;
FPSCamera2.enabled = !FPSCamera2.enabled;
}
//MOVIMIENTO
if (FPSCamera.enabled) {
if (Input.GetKey (KeyCode.W)) {
transform.Translate (0, 0, 0.1f * run);
}
if (Input.GetKey (KeyCode.D)) {
transform.Translate (0.1f * run, 0, 0);
}
if (Input.GetKey (KeyCode.A)) {
transform.Translate (-0.1f * run, 0, 0);
}
if (Input.GetKey (KeyCode.S)) {
transform.Translate (0, 0, -0.1f * run);
}
if (Input.GetKey (KeyCode.LeftShift)) {
run = 2;
} else {
run = 1;
}
if (Input.GetKeyDown (KeyCode.Space)) {
canJump = true;
}
}
if (FPSCamera2.enabled) {
if (Input.GetKey (KeyCode.W)) {
transform.Translate (0, 0, 0.1f * run);
}
if (Input.GetKey (KeyCode.D)) {
transform.Translate (0.1f * run, 0, 0);
}
if (Input.GetKey (KeyCode.A)) {
transform.Translate (-0.1f * run, 0, 0);
}
if (Input.GetKey (KeyCode.S)) {
transform.Translate (0, 0, -0.1f * run);
}
if (Input.GetKey (KeyCode.LeftShift)) {
run = 2;
} else {
run = 1;
}
if (Input.GetKeyDown (KeyCode.Space)) {
canJump = true;
}
}
}
}