• 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 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 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.

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

212 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 avatar image avatar image avatar image avatar image

Related Questions

PhotonUnity player move object problem ! 1 Answer

I keep getting this error: Assets/Photon/PhotonRealtime/Code/Room.cs(309,42): error CS0115: `Photon.Realtime.Room.InternalCacheProperties()' is marked as an override but no suitable method found to override 0 Answers

Keeping an object in a multiplayer scene, when a player joins. 3 Answers

C# Photon Networking - Preventing duplicate GameObjects from spawning on Join. 1 Answer

How both players can control the soccer ball in 2 player football game 1 Answer

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