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 /
avatar image
0
Question by kotasugi2007 · Apr 18, 2020 at 12:34 PM · multiplayerphotonfirst person shooter

HELP ME ON PHOTON. UNITY 3D MULTIPLAYER FPS

Hello, I just started to create FPS multiplayer games by following a tutorial made by Welton King. Link: https://www.youtube.com/watch?v=MAAxL6Q_ElE&list=PL6PsTmPNvw0eZirNDjO8dL0Y6X0ZFGaMt I am stuck at #14. Somehow when I equip the weapon, it doesn't show on another person's screen. I have the same code as video. But somehow it seems like it is not working.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using Photon.Pun;
 
 public class Weapon : MonoBehaviourPunCallbacks
 {
     #region Variables
 
     public Gun[] loadout;
     public Transform WeaponParent;
     public GameObject bulletholePrefab;
     public LayerMask canBeShot;
 
     private float currentCooldown;
     private int currentIndex;
     private GameObject currentWeapon;
 
     #endregion
 
     #region MonoBehaviour Callbacks
 
     // Update is called once per frame
     void Update()
     {
         if (!photonView.IsMine) return;
 
         if (Input.GetKeyDown(KeyCode.Alpha1)) photonView.RPC("Equip", RpcTarget.All, 0); 
         if(currentWeapon != null)
         {
             Aim((Input.GetMouseButton(1)));
 
             if(Input.GetMouseButtonDown(0) && currentCooldown <= 0)
             {
                 photonView.RPC("Shoot", RpcTarget.All);
             }
 
             //Weapon position elasticity
             currentWeapon.transform.localPosition = Vector3.Lerp(currentWeapon.transform.localPosition, Vector3.zero, Time.deltaTime * 4f);
 
             //cooldown
             if (currentCooldown > 0) currentCooldown -= Time.deltaTime;
         }
     }
 
     #endregion
 
     #region Private Methods
 
     [PunRPC]
     void Equip(int ind)
     {
         if (currentWeapon != null) Destroy(currentWeapon);
 
         currentIndex = ind;
 
         GameObject newEquipment = Instantiate (loadout[ind].prefab, WeaponParent.position, WeaponParent.rotation, WeaponParent) as GameObject;
         newEquipment.transform.localPosition = Vector3.zero;
         newEquipment.transform.localEulerAngles = Vector3.zero;
         newEquipment.GetComponent<Sway>().enabled = photonView.IsMine;
 
         currentWeapon = newEquipment;
     }
 
     void Aim(bool isAiming)
     {
         Transform anchor = currentWeapon.transform.Find("Anchor");
         Transform state_ads = currentWeapon.transform.Find("States/ADS");
         Transform state_hip = currentWeapon.transform.Find("States/Hip");
 
         if (isAiming)
         {
             //aim
             anchor.position = Vector3.Lerp(anchor.position, state_ads.position, Time.deltaTime * loadout[currentIndex].aimSpeed);
         }
         else
         {
             //hip
             anchor.position = Vector3.Lerp(anchor.position, state_hip.position, Time.deltaTime * loadout[currentIndex].aimSpeed);
         }
     }
 
     [PunRPC]
     void Shoot()
     {
         Transform spawn = transform.Find("Cameras/Normal Camera");
 
         //Blooom
         Vector3 t_bloom = spawn.position + spawn.forward * 1000f;
         t_bloom += Random.Range(-loadout[currentIndex].bloom, loadout[currentIndex].bloom) * spawn.up;
         t_bloom += Random.Range(-loadout[currentIndex].bloom, loadout[currentIndex].bloom) * spawn.right;
         t_bloom -= spawn.position;
         t_bloom.Normalize();
 
         //Cooldown
         currentCooldown = loadout[currentIndex].fireRate;
 
         //Raycast
         RaycastHit hit = new RaycastHit();
         if (Physics.Raycast(spawn.position, t_bloom, out hit, 1000f, canBeShot))
         {
             GameObject newHole = Instantiate(bulletholePrefab, hit.point + hit.normal * 0.001f, Quaternion.identity) as GameObject;
             newHole.transform.LookAt(hit.point + hit.normal);
             Destroy(newHole, 5f);
 
             if(photonView.IsMine)
             {
                 //Shooting other player on network
                 if(hit.collider.gameObject.layer == 11)
                 {
                     //RPC Call ro Damage Player Gose Here
                 }
             }
         }
 
         //gun fx
         currentWeapon.transform.Rotate(-loadout[currentIndex].recoil, 0, 0);
         currentWeapon.transform.position -= currentWeapon.transform.forward * loadout[currentIndex].kickback;
     }
     #endregion
 }
 

↑ | | That is my weapon script. Sorry for putting the whole thing but I really need help with this script.

alt text alt text SOMEONE PLEASE HELP ME

screenshot-1.png (470.4 kB)
screenshot-2.png (307.1 kB)
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

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

215 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

Related Questions

Player Smoothness across network (PUN) 0 Answers

Networking: Keep room alive without active players 0 Answers

Oculus Quest Photon Network bugs connecting players 2 Answers

How many current players will I get daily if I have 10k installs 1 Answer

Problem with PhotonView.RPC 4 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