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 /
  • Help Room /
avatar image
0
Question by Lable · May 10, 2019 at 03:00 AM · instantiateparticlesphotonnoobpun

How do you Instantiate particles using Photon?

I'm trying to make sure everyone can see each other's spells when they cast them using PhotonView (hint: I have no idea how anything in Photon works) What do I have to do to get my current script to work online?

 using UnityEngine;
 using Valve.VR;
 
 public class Wizard_Spell : MonoBehaviour
 {
 
     public GameObject Spell1;
     public SteamVR_Action_Boolean TriggerClick;
     public SteamVR_Input_Sources inputSource1;
 
     private void OnEnable()
     {
         TriggerClick.AddOnStateDownListener(CastSpell, inputSource1);
     }
 
     private void OnDisable()
     {
         TriggerClick.RemoveOnStateDownListener(CastSpell, inputSource1);
     }
 
    private void CastSpell(SteamVR_Action_Boolean fromAction, SteamVR_Input_Sources fromSource)
     {
             Instantiate(Spell1, transform.position, transform.rotation);
     }
 
 }
 
 
 
 
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
1

Answer by Captain_Pineapple · May 10, 2019 at 08:09 AM

Hey there,

before you start on this please read the documentations on photon. the most important things for you will be Remove Procedure Calls, the general pun photon view doku and how to create and join rooms

Do this before you continue working on this!

When you think you understood the basics then add a photon view to your current player object. This will be the component that manages incoming and outgoing messages to this object. If you have an object that you want to sync in position, ad a photon transform view. Only use custom serialization code if you really have to. In general i'd suggest to keep the number of photon views as small as possible. For this reason i'd take your current WizardSpell script and make it call a function on your main character behaviour to use that photon view for "networked spellcasting".

In connection to this i'd suggest you read into Object Pooling. This will create a static class for you from which you can request Object Instances. If you assign an ID to each of your spells you can easily create them without any performance issues.

For now let's assume that you add object pooling later on and for now just have some public static GameObject[] allSpellPrefabs; allSpellPrefabs will have all spells as prefabs in one array and since its public static you can access it from anywhere. Then you can use the following function to cast spells over the network:

     [PunRPC]
     public void castSpell (int index)
     {
         //this checks if this object instance belongs to the local player:
         if(photonView.IsMine)
         {
             //call this method for all other players in the current room:
             photonView.RPC("castSpell", PhotonTargets.Others, index);
         }
         //instantiate the requested spell by index. Get an object
         Instantiate(Spell1, transform.position, transform.rotation);
     }

(so to call this replace the instanciation call on your wizardspell script by some means to find you local player object whatever it may be called and call the castspell function on it.)

Hope this helps and you did not drown in new knowledge. If something needs further clarification let me know and i will try to elaborate a bit more on it.

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

208 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 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

Racing game using PUN 2 0 Answers

How do i use RPC's to set a object active in the hierarchy for all Players in the room and also how do i synchronize UI events focused on a VideoPlayer (Play, Pause etc.)) 0 Answers

Photon Player instantiate position 1 Answer

Photon transform view not syncing despite other objects transform view working perfectly 1 Answer

PhotonPun RPC functions Doesnt Work For Both the Players 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