Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 frankyboy450 · Oct 22, 2013 at 08:55 PM · c#networklayersculling mask

Using layers to show/hide different players

Hi. Most games are made so other people in a multiplayer game sees the whole person and you only see your own hands + gun, and the same goes for the other way around.

I need to Check if the NetworkView is mine and do this: Set other player's layer to "OtherPlayer" and show them. Set other player's weapon layer to "OtherWeapon" and hide them. Set own player's layer to "OwnPlayer" and hide that layer. Set own player's weapon layer to "OwnWeapon" and show it.

Can someone explain to me how to change the culling mask via code? because the script reference isn't that helping :/

Sorry if this thread was confusing, I wasn't sure on how to describe my question.

Thanks if you're able to help.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Tomer-Barkan · Oct 22, 2013 at 09:16 PM

I'd think most games would actually have the same model, and the difference would be the camera placement, if you place the camera in a certain location you would only see your arms/weapons while you would see the full body of other players.

Still, if you want to go this way, to set the culling mask of a camera programatically use the following command:

 camera.cullingMask = LayerMask.NameToLayer("Layer1") | LayerMask.NameToLayer("Layer2");

where "Layer1" and "Layer2" are names of layers you want the camera to show (any number of layers can be BITWISE ORed). To set the layer of an object is the same, except you can only provide one:

 gameObject.layer = LayerMask.NameToLayer("Layer1");
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 frankyboy450 · Oct 24, 2013 at 05:01 PM 0
Share

Answers.unity3d.com died yesterday so I posted a forum post about it ins$$anonymous$$d. now this site is back again.

I set the Culling mask on my camera to hide "OtherWeapon" and "OwnPlayer" and attached this script to my player prefab that get's spawned.

     using UnityEngine;
 
     using System.Collections;
 
     
 
     /// <summary>
 
     /// Just a test script. Not important.
 
     /// </summary>
 
     
 
     public class LayerChange : $$anonymous$$onoBehaviour {
 
         
 
         private Transform myTransform;
 
         
 
         private Transform cameraHeadTransform;
 
         
 
         private Transform soldier$$anonymous$$odelTransform;
 
         
 
         private Transform weaponTransform;
 
         
 
         // Use this for initialization
 
         void Start ()
 
         {
 
             myTransform = transform; // set myTransform to the transform of the scripts parent.
 
             
 
             cameraHeadTransform = myTransform.FindChild("CameraHead"); // Find the cameraHead
 
             
 
             soldier$$anonymous$$odelTransform = myTransform.FindChild("Soldier"); // Find the soldier $$anonymous$$odel
 
             
 
             weaponTransform = cameraHeadTransform.FindChild("Weapons"); // Find the weapons under CameraHead
 
             
 
             //if the script is running on my player, set my player's layer to OwnPlayer 
 
             //and my weapon to OwnWeapon
 
                 
 
             if(networkView.is$$anonymous$$ine == true)
 
             {
 
                 soldier$$anonymous$$odelTransform.gameObject.layer = Layer$$anonymous$$ask.NameToLayer("OwnPlayer");
 
                 weaponTransform.gameObject.layer = Layer$$anonymous$$ask.NameToLayer("OwnWeapon");
 
             }
 
             
 
             
 
             //If the script isn't running on my player, set the player's layer to Other Player
 
             //and the player's weapon's tag to OtherWeapon
 
             
 
             if(networkView.is$$anonymous$$ine == false)
 
             {
 
                 soldier$$anonymous$$odelTransform.gameObject.layer = Layer$$anonymous$$ask.NameToLayer("OtherPlayer");
 
                 weaponTransform.gameObject.layer = Layer$$anonymous$$ask.NameToLayer("OtherWeapon");
 
             }
 
         }
 
         
 
         // Update is called once per frame
 
         void Update () {
 
         
 
         }
 
     }

For some reason the player can't move and the GameObject get's called "BlueTeam(copy)" ins$$anonymous$$d of the name the player writes when they enter the server. Everything works fine if I remove the script except that everyone sees each others player and weapon+arms model.

avatar image Tomer-Barkan · Oct 27, 2013 at 04:46 PM 0
Share

The code seems fine to me (don't know what networkView.is$$anonymous$$ine does though). Are you getting any exceptions at all? If you disable this code, does it not call "BlueTeam(copy)"? the "(copy)" part is added when you instantiate a prefab programatically.

avatar image frankyboy450 · Oct 28, 2013 at 12:22 AM 0
Share

I got it working, Thanks for the help ;) If you attach a Network View to a GameObject, then you can check if the script is attached to your player(networkView.is$$anonymous$$ine == true) or if it's attached to another persons player.

so you can disable the script on other players if you want to.

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

15 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

Related Questions

A game object can only be in one layer. The layer needs to be in the range [0...31] 6 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

How does this script identify other players? C# 1 Answer

Flip over an object (smooth transition) 3 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