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 unity_bfvNwgs4mDhzgw · Dec 02, 2021 at 09:10 AM · multiplayerphotonportal

Does anyone know how to sync portal shooting for my portal game? [PHOTON PUN 2]

Probably a noob Question but How would i sync a RaycastHit value (i also have a portalcamera script if you want to see it) My code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Photon.Pun;
 
 public class PortalShooter : MonoBehaviourPun
 {
     public GameObject orangePortalPrefab;
     public GameObject bluePortalPrefab;
 
     public GameObject blueCameraPrefab;
     public GameObject orangeCameraPrefab;
 
     public Material orangeOpen;
     public Material orangeClosed;
     public Material blueOpen;
     public Material blueClosed;
 
     private GameObject orangePortal;
     private GameObject bluePortal;
     private GameObject orangeCamObject;
     private GameObject blueCamObject;
 
     private PortalCamera orangeCamera;
     private PortalCamera blueCamera;
     public AudioSource Blue, Orange;
     public int id;
     public Transform cur;
     RaycastHit hit;
 
     // Use this for initialization
     void Start()
     {
         transform.name = GetComponent<PhotonView>().ViewID.ToString();
         orangePortal = Instantiate<GameObject>(orangePortalPrefab);
         bluePortal = Instantiate<GameObject>(bluePortalPrefab);
         orangeCamObject = Instantiate<GameObject>(orangeCameraPrefab);
         blueCamObject = Instantiate<GameObject>(blueCameraPrefab);
         orangePortal.GetComponentInChildren<Teleporter>().destination = bluePortal.transform.Find("Destination");
         bluePortal.GetComponentInChildren<Teleporter>().destination = orangePortal.transform.Find("Destination");
         orangeCamera = orangeCamObject.GetComponent<PortalCamera>();
         orangeCamera.associatedPortal = orangePortal.transform.Find("Surface");
         orangeCamera.oppositePortal = bluePortal.transform.Find("Surface");
         orangeCamera.associatedPortal.GetComponent<Renderer>().sharedMaterial = orangeClosed;
         orangeCamera.playerCam = transform;
         blueCamera = blueCamObject.GetComponent<PortalCamera>();
         blueCamera.associatedPortal = bluePortal.transform.Find("Surface");
         blueCamera.oppositePortal = orangePortal.transform.Find("Surface");
         blueCamera.associatedPortal.GetComponent<Renderer>().sharedMaterial = blueClosed;
         blueCamera.playerCam = transform;
     }
 
     // Update is called once per frame
     void Update()
     {
         if (Input.GetButtonDown("Fire2") && photonView.IsMine)
         {
 
             PlacePortal("OrangePortalv2(Clone)");
             Orange.Play();
         }
         else if (Input.GetButtonDown("Fire1") && photonView.IsMine)
         {
             PlacePortal("BluePortalv2(Clone)");
             Blue.Play();
         }
     }
 
     private void UpdatePortalsMaterials()
     {
         if (bluePortal.activeSelf)
         {
             orangeCamera.associatedPortal.GetComponent<Renderer>().sharedMaterial = orangeOpen;
         }
         else
         {
             orangeCamera.associatedPortal.GetComponent<Renderer>().sharedMaterial = orangeClosed;
         }
         if (orangePortal.activeSelf)
         {
             blueCamera.associatedPortal.GetComponent<Renderer>().sharedMaterial = blueOpen;
         }
         else
         {
             blueCamera.associatedPortal.GetComponent<Renderer>().sharedMaterial = blueClosed;
         }
     }
 
     private void PlacePortal(string ObjectName)
     {
         GameObject portal;
         portal = GameObject.Find(ObjectName);
         if (Physics.Raycast(transform.position, transform.forward, out hit))
         {
             photonView.RPC("ReallyPlaceThem", RpcTarget.All, ObjectName);
         }
     }
 
     private bool ValidatePortalPosition(GameObject portal, Collider associatedSurface)
     {
         Transform up, down, left, right;
         up = portal.transform.Find("PortalTop");
         down = portal.transform.Find("PortalBottom");
         left = portal.transform.Find("PortalLeft");
         right = portal.transform.Find("PortalRight");
 
         return IsOnCollider(up, associatedSurface) &&
         IsOnCollider(down, associatedSurface) &&
         IsOnCollider(left, associatedSurface) &&
         IsOnCollider(right, associatedSurface);
     }
 
     private bool IsOnCollider(Transform point, Collider col)
     {
         RaycastHit hit;
         if (Physics.Raycast(point.position, -point.forward, out hit, 0.1f))
         {
             return hit.collider == col;
         }
         return false;
     }
 
 
     [PunRPC]
     public void ReallyPlaceThem(string Obj)
     {
         GameObject portal;
         portal = GameObject.Find(Obj);
         if (hit.transform.tag != "OpenableSurface")
         {
             return;
         }
         portal.transform.position = hit.point;
         Vector3 lookPos = transform.position;
         lookPos.y = portal.transform.position.y;
         portal.transform.LookAt(lookPos);
 
         float surfaceAngle = Vector3.Angle(hit.normal, Vector3.up);
         if (surfaceAngle < 35.0f || surfaceAngle > 145.0f)
         {
             portal.transform.LookAt(hit.point + hit.normal, transform.up);
         }
         else
         {
             portal.transform.LookAt(hit.point + hit.normal);
         }
 
         portal.transform.Translate(0.0f, 0.0f, 0.01f);
         bool validPosition = ValidatePortalPosition(portal, hit.collider);
         if (validPosition)
         {
             BodyDetector detector = portal.GetComponentInChildren<BodyDetector>();
             detector.associatedSurface = hit.collider;
             detector.InitializeCollidersList();
             portal.SetActive(true);
 
             if (portal == orangePortal)
             {
                 orangeCamera.RecalculateHolePositions();
                 detector.otherDetector = bluePortal.GetComponentInChildren<BodyDetector>();
             }
             else if (portal == bluePortal)
             {
                 blueCamera.RecalculateHolePositions();
                 detector.otherDetector = orangePortal.GetComponentInChildren<BodyDetector>();
             }
         }
         UpdatePortalsMaterials();
     }
 }


Comment
Add comment · Show 3
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 unity_bfvNwgs4mDhzgw · Dec 02, 2021 at 09:11 AM 0
Share

by the way i don't know why it does all of those weird spaces between all lines

avatar image Captain_Pineapple unity_bfvNwgs4mDhzgw · Dec 02, 2021 at 11:03 AM 1
Share

please try to sort that out. That code is unreadable..


If your issue is just that you cannot send a RayCastHit object as argument of a PunRPC then please look into creating custom datatypes for RPCs. There is a documentation on how to do that in PUN.


Please describe your issue a more thoroughly next time. As a rule of thumb if you have 30x more lines of code than you have text for your description something definetly is wrong.

avatar image Bunny83 Captain_Pineapple · Dec 02, 2021 at 12:04 PM 1
Share

I've quickly fixed it.

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

How to have the Scenes download upon request? 1 Answer

How to get all created rooms and join any one of them in PHOTON 2 Answers

Networking (?) 1 Answer

How can i close or make it invisible photon multiplayer room? 1 Answer

How to make a host-client server? 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