Change between players with a button
Hi :D Im trying to make a game of which I'll not say in what it consists since I think its a very good idea but I have problems to do it... x)
Well, the thing is that I have to "switch" position with an npc and control it. I dont actually know how should I do this since I dont find the way to change the camera in the FPS Controller. It'd be something like this.
I aim to another "npc"(rn it'd be just a box), click G and Im "him". I've tried searching and I found some things like that but none seems to work properly...
http://answers.unity3d.com/questions/16146/changing-between-cameras.html
http://answers.unity3d.com/questions/239700/switch-camera-on-input-in-c.html
http://answers.unity3d.com/questions/14381/main-camera-switch.html
Thanks in advance.
Just found the way to change the camera. The next step is to make the other "player" to move. Thanks anyway :).
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FifthSouls$$anonymous$$ovController : $$anonymous$$onoBehaviour {
//CA$$anonymous$$ARA
public Camera FPSCamera;
public Camera FPSCamera2;
public float horizontalSpeed;
public float verticalSpeed;
float h;
float v;
//$$anonymous$$OVI$$anonymous$$IENTO
public float run = 1;
public int forceConst = 4;
private bool canJump;
private Rigidbody selfRigidbody;
// Use this for initialization
void Start () {
//CA$$anonymous$$ARA
FPSCamera.enabled = true;
FPSCamera2.enabled = false;
//$$anonymous$$OVI$$anonymous$$IENTO
selfRigidbody = GetComponent<Rigidbody> ();
}
void FixedUpdate (){
if (canJump) {
canJump = false;
selfRigidbody.AddForce (0, forceConst, 0, Force$$anonymous$$ode.Impulse);
}
}
// Update is called once per frame
void Update () {
//CA$$anonymous$$ARA
h = horizontalSpeed * Input.GetAxis ("$$anonymous$$ouse X");
v = verticalSpeed * Input.GetAxis ("$$anonymous$$ouse Y");
transform.Rotate (0,h,0);
FPSCamera.transform.Rotate (-v,0,0);
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.G)) {
FPSCamera.enabled = !FPSCamera.enabled;
FPSCamera2.enabled = !FPSCamera2.enabled;
}
//$$anonymous$$OVI$$anonymous$$IENTO
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.W)) {
transform.Translate (0, 0, 0.1f * run);
}
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.D)) {
transform.Translate (0.1f * run, 0, 0);
}
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.A)) {
transform.Translate (-0.1f * run, 0, 0);
}
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.S)) {
transform.Translate (0, 0, -0.1f * run);
}
if (Input.Get$$anonymous$$ey ($$anonymous$$eyCode.LeftShift)) {
run = 2;
} else {
run = 1;
}
if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Space)) {
canJump = true;
}
}
}