Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 /
avatar image
0
Question by imM4TT · Dec 14, 2017 at 10:56 AM · cameranetwork

Trying to set multiple camera

Hi there is my code that i attached on the player :

 public Camera playerCamera;
 public Camera playerDeadCamera;
 
 void Start () {
     ShowPlayerView();
 }

 void OnCollisionEnter(Collision col)
 {
     if (col.gameObject.tag == "Enemy")
     {
         ShowPlayerDeadView();
     }
 }
 
 public void ShowPlayerView()
 {
     playerCamera.enabled = true;
     playerDeadCamera.enabled = false;
 }
 
 public void ShowPlayerDeadView()
 {
     playerDeadCamera.enabled = true;
     playerCamera.enabled = false;
 }

PlayerCamera have a smooth follow script which targeting Player. I attached these camera to the Player script. That works on MonoBehaviour ofc but when i try to apply this for a multiplayer script that tell me there isnt camera rendering. Can you help me please

Comment
Add comment · Show 4
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 Codez · Dec 14, 2017 at 11:59 AM 0
Share

By applying it to a mulitplayer script, do you mean you're using 'NetworkingBehaviour'?

avatar image imM4TT Codez · Dec 14, 2017 at 12:15 PM 0
Share

Yes sure. Camera arent working at all...

avatar image Codez imM4TT · Dec 14, 2017 at 12:25 PM 0
Share

Trying to understand specifically what's happening, cause you haven't given much explanation around the error other than 'Cameras not rendering' (which I'm assu$$anonymous$$g happens when you press play). Does this happen immediately when you press play? Are there only two cameras? Only one player present?

Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Codez · Dec 14, 2017 at 11:06 PM

I believe the problem comes in with the 'spawning prefabs' part. For the camera to follow a spawned player, it will need to locate the player object first. I would suggest looking at this Unity Tutorial https://unity3d.com/es/learn/tutorials/projects/2d-ufo-tutorial/following-player-camera Hope this helps :)

Comment
Add comment · Show 4 · Share
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 imM4TT · Dec 15, 2017 at 02:50 PM 0
Share

I got an error on your link, ill try to find for my part

avatar image imM4TT · Dec 15, 2017 at 08:53 PM 0
Share

I cant found, im getting stuck, tell me please if you know how resolve it

avatar image ElijahShadbolt · Dec 15, 2017 at 09:07 PM 0
Share

@Codez, never end your links with a full stop, it will break. https://unity3d.com/es/learn/tutorials/projects/2d-ufo-tutorial/following-player-camera

avatar image Codez ElijahShadbolt · Dec 16, 2017 at 02:19 AM 0
Share

Ah, thanks Sublime; I wasn't aware links included those full-stops. It's fixed now.

avatar image
1

Answer by ElijahShadbolt · Dec 15, 2017 at 09:15 PM

If you've got two prefabs, one for Player and one for PlayerCamera, you cannot just set the smooth follow to reference the Player prefab. When the Player and PlayerCamera are instantiated in this case, the reference will still be to the Player prefab, not the instantiated Player object.


You will need to create a custom script, and when the Player and PlayerCamera are instantiated, assign the smooth follow reference to the newly created Player instance.


Or if you have the prefabs already instantiated in the scene in Edit mode, in the smooth follow Inspector assign the reference to the Scene objects, not the prefabs.

Comment
Add comment · Show 3 · Share
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 imM4TT · Dec 15, 2017 at 09:53 PM 0
Share

Thanks !
Do you think this script can work or not ? ( I try this tomorrow )
Camera.mainCamera.GetComponent(SmoothFollow).target = player;

avatar image Codez imM4TT · Dec 16, 2017 at 02:18 AM 0
Share

Yeah, it sounds like your on the right track. I got something similar working and hopefully it does for you too. in your player controller script, try adding: public override void OnStartLocalPlayer() { Camera.main.GetComponent().setTarget(gameObject.transform); } And then in the Update function in the 'SmoothFollow' script, add this: public void setTarget(Transform target) { playerTransform = target; } (https://answers.unity.com/questions/1157437/making-my-camera-follow-player-in-multiplayer.html)

avatar image ElijahShadbolt · Dec 16, 2017 at 02:10 AM 1
Share

You'll need to edit the SmoothFollow script (in project folder Assets > Standard Assets > Utility) and change private Transform target; to

 public Transform target;

Then when you instantiate 'player', you could use

 Camera.main.GetComponent<SmoothFollow>().target = player.transform;
avatar image
1

Answer by programer717 · Dec 16, 2017 at 04:07 AM

@imM4TT the cameras need to be on the same render to be able to switch between cameras make sure you set one to enabled to false and one to true I don't see any thing wrong with your script at first glance.

Comment
Add comment · Show 1 · Share
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 imM4TT · Dec 16, 2017 at 02:40 PM 1
Share

Thanks you all, that's working now =) I just need to adjust the camera settings and it's right

avatar image
0

Answer by imM4TT · Dec 14, 2017 at 03:11 PM

The problem is that if I just set my playerCamera as childrens of my player, the smooth follow isnt working. So the camera is following the player but the smooth follow script is like deactivated. And when I try to attach the cameraPlayer ( with smooth follow script ) to the Player by the inspector, this isnt working. I need help please. Ill post a " solution " if i found ...

Comment
Add comment · Show 1 · Share
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 imM4TT · Dec 14, 2017 at 09:30 PM 0
Share

Someone knows how to make it works ?

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.

Follow this Question

Answers Answers and Comments

134 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

Related Questions

Multiplayer| Attaching camera to player (if i am the owner 1 Answer

Network Manager GUI 1 Answer

Network Moving Help. 1 Answer

On Network GameObject Movment and Rotation Problem. 1 Answer

Problem with camera and gun in FPS game 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges