• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Nightm4reProds · Oct 10, 2017 at 01:58 AM · fpsfps controllernpcswitchingcamera controls

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nightm4reProds · Oct 10, 2017 at 09:31 PM 0
Share

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;
     }





     
 }

}

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

142 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Parented Object moves weirdly in FPS Standard Asset Camera 0 Answers

Full body gun switcher for animations? 1 Answer

First person shooter : Footsteps! 1 Answer

Y Mouse Movement without the tilting 0 Answers

Character sometimes moves faster when I jump and start moving at the same time 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges