Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
4 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 WerewoofPrime · Apr 20 at 03:58 PM · networkinginstantiatephotonrandom.rangestatic variable

script always instantiates monster even when its not supposed to?

hello, I am making a multiplayer game using photon pun 2. when the player spawns in, if he is master client he is able to press a button called "start" when this button is pressed, all the players in the scene (only been tested with 2 players) are supposed to randomize a number over and over until one of them gets their number to equal 5, then that player instantiates a monster gameobject and deletes itself. (the player is now controlling the monster gameobject) however the problem is both players turn into the monster regardless of what happens. it always has a delay where both players are randomizing then one will turn, then the other. does anyone know why this is happening? here is the script on the starting gameobject that instantiates the monsters: (as you can see i am setting a static variable from another script (GameController) called "HasMonster" to true when a player turns into the monster. the player is only supposed to instantiate the monster if its variable lands on five and HasMonster is FALSE, which is why i set that variable to false after a player is turned into a monster.)

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Photon.Pun;
 
 public class PlayerStart : MonoBehaviour
 {
     private bool ChangedAlready = false;
     [SerializeField]
     private bool IsMonster = false;
     [SerializeField]
     private int MonsterRandom = 0;
     public bool GotKilled = false;
 
     void MonsterChoose()
     {
        if (IsMonster == false && GameController.HasMonster == true)
        {
            NotMonster();
            PhotonView photonView = PhotonView.Get(this);
           photonView.RPC("DestroyPlayer", RpcTarget.All);
        }
        if (GameController.HasMonster == false && EventManager.DidGameStart == true)
        {
            MonsterRandom = Random.Range(1, 100);
        }
        if (MonsterRandom == 5)
        {            
             PhotonView photonView = PhotonView.Get(this);
             photonView.RPC("DestroyPlayer", RpcTarget.All);
             IsMonster = true;
             GameController.HasMonster = true;
            MonsterDetect();  
             
        }
     }
 
     [PunRPC]
     void DestroyPlayer()
     {
         Destroy(gameObject);
     }
 
    
     void NotMonster()
     {
         if(ChangedAlready == false)
         {           
             PhotonNetwork.Instantiate("PlayerInstance", transform.position, transform.rotation);          
             Debug.Log("PLAYER");                       
             ChangedAlready = true;           
         } 
     }
 
     
     void MonsterDetect()
     {
         if(ChangedAlready == false)
         {           
             PhotonNetwork.Instantiate("MonsterInstance", transform.position, transform.rotation);           
             Debug.Log("MONSTER");
             GameController.HasMonster = true;
             ChangedAlready = false;            
         }
     }
   
 
  
     void FixedUpdate()
     {
         MonsterChoose();
     }
 
 
 }
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

Answer by WerewoofPrime · Apr 20 at 11:25 PM

SOLVED! I simply had to change the GameController.HasMonster variable via an RPC!!! :D

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

210 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

Related Questions

Photon Networking Instantiating Problem 0 Answers

Photon Unity Networking - Player Camera Instantiate 0 Answers

Proper way to instantiate projectile in PUN 1 Answer

(Clone) from Instantiated Prefabs over Network 1 Answer

How do I Photon Instantiate a scene object randomly from a list of objects? 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