Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 Sandr0G · Dec 29, 2012 at 05:02 PM · instantiatemultiplayerphotoncomponentcloud

How to add a component to a prefab

I am trying to add a component to a prefab but I can't get it to work. I want the component to be added only when I join a room (multiplayer). This is the code that I have right now.

 var pms : PlayerMovementScript;
 
 function OnJoinedRoom()
    {    //Initialize the player and add components
        player = PhotonNetwork.Instantiate("Player Capsule", Vector3.zero, Quaternion.identity, 0);
        pms = player.AddComponent("PlayerMovementScript");
        pms.enabled = true;
        myPlayerPv = player.GetComponent(PhotonView);
    }

I want it to be added only when I join the room so that I can control only my player. The component that I am trying to add is the PlayerMovementScript. Thanks.

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 valax · Dec 29, 2012 at 07:52 PM 0
Share

Why not attach it to the character prefab and add a boolean variable to check whether or not they're in the room. If so, do: pms = GetComponent (Player$$anonymous$$ovementScript); pms.enabled = true;

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tobiass · Jan 02, 2013 at 05:29 PM

You don't need to attach a script for this to work. You can add one but be aware that remote players won't do the same! RPCs and OnSerializePhotonView() should be defined in scripts that are active on all clients.

If you want to control only your own character, simply check the PhotonView.isMine property. This will be true for the GOs a user instantiated and also for the scene objects on the client that is the MasterClient. Only PhotonView's that belong to a player have a valid user though.

In the Marco Polo Tutorial, we use isMine and also show another way to keep control over "owned" objects: http://doc.exitgames.com/photon-cloud/Marco_Polo_Tutorial/#cat-PUN%20Tutorials

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

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

10 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

Related Questions

Photon enable/disable objects on all views? 1 Answer

trying to catch photonNetwork instantiated object of another user 0 Answers

Instantiating player when creating a new room in photon not working. 0 Answers

PUN 2 : Impossible to applied damage to all player in overlapSphere created by a bomb ? 0 Answers

Photon Instantiate 2 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