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 tatto123321 · Jul 17, 2017 at 08:12 AM · script.photongunweaponview

Photon Weapon View

Hello friends. I'm doing an online game using photon. But I do not see the gun when I do it. Please help us how to fix it.

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 ChristianSimon · Jul 17, 2017 at 08:32 AM 0
Share

Hi,

please share us some more details about what you want to achieve and also some code if it is a coding issue.

Do you want to synchronize the weapons the characters have equipped?

avatar image tatto123321 ChristianSimon · Jul 17, 2017 at 09:29 AM 0
Share

if there isn't a problem I want to you to send my game files. I made some mistakes. Can you fix that please?

avatar image tatto123321 ChristianSimon · Jul 17, 2017 at 09:50 AM 0
Share

yes ı want synchronize the weapons the characters have equipped

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by tatto123321 · Jul 17, 2017 at 09:07 AM

private Animator anim; private AudioSource audioSource;

 public float range = 100f;
 public int bulletsPerMag = 30;
 public int bulletsLeft = 200;
 public int currentBullets;

 public enum ShootMode {Auto,Semi }
 public ShootMode shootingMode;

 public Transform shootPoint;
 public ParticleSystem muzzleFlash;
 public AudioClip shotSound;
 public AudioClip reloadSound;

 float damage = 20f;

 public GameObject hitParticles;
 public GameObject bulletImpact;

 public float fireRate = 0.08f;
 float fireTimer;

 private bool isReloading;
 private bool shootInput;
 private bool isAiming;

 private Vector3 originalPosition;
 public Vector3 aimPosition;
 public float aodSpeed;

 public float maxBulletSpreadAngle = 15.0f;

 void Start () {
     anim = GetComponent<Animator>();

     audioSource = GetComponent<AudioSource>();

     currentBullets = bulletsPerMag;

     originalPosition = transform.localPosition;
 }

 void Update () {

     switch (shootingMode)
     {
         case ShootMode.Auto:
             shootInput = Input.GetButton("Fire1");
             break;

         case ShootMode.Semi:
             shootInput = Input.GetButtonDown("Fire1");
             break;
     }

     if (shootInput)
     {
         if (currentBullets > 0)
         {
             Fire();
         }
         else if(bulletsLeft > 0 )
         {
             DoReload();
         }   
     }

     if (Input.GetKeyDown(KeyCode.R))
     {
         if (currentBullets < bulletsPerMag && bulletsLeft > 0)
             DoReload();
     }

     if (fireTimer < fireRate)
         fireTimer += Time.deltaTime;

     AimDownSights();
 }

 private void AimDownSights()
 {
     if (Input.GetButton("Fire2"))
     {
         transform.localPosition = Vector3.Lerp(transform.localPosition, aimPosition, Time.deltaTime * aodSpeed);
         isAiming = true;
     }
     else
     {
         transform.localPosition = Vector3.Lerp(transform.localPosition, originalPosition, Time.deltaTime * aodSpeed);
         isAiming = false;
     }
 }

 void FixedUpdate()
 {
     AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(0);

     isReloading = info.IsName("Reload");

     anim.SetBool("Aim", isAiming);
     //if (info.IsName("Shot")) anim.SetBool("Shot", false);
 }

 public void Fire()
 {
     if (fireTimer < fireRate || currentBullets <= 0 || isReloading) return;

     RaycastHit hit;
     
     Vector3 fireDirection = shootPoint.transform.forward;

     Quaternion fireRotation = Quaternion.LookRotation(fireDirection);

     Quaternion randomRotation = Random.rotation;

     fireRotation = Quaternion.RotateTowards(fireRotation, randomRotation, Random.Range(0.0f, maxBulletSpreadAngle));

     if (Physics.Raycast(shootPoint.position, fireRotation * Vector3.forward, out hit, range))
     {
         Health h = hit.transform.GetComponentInParent<Health>();

         if(h != null)
         {
             h.GetComponent<PhotonView>().RPC("TakeDamage", PhotonTargets.AllBuffered, damage);
         }

         Debug.Log(hit.transform.name + "found!");

         GameObject hitParticleEffect = Instantiate(hitParticles, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
         GameObject bulletHole = Instantiate(bulletImpact, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal));

         Destroy(hitParticleEffect, 1f);
         Destroy(bulletHole, 2f);
        

     }
     anim.CrossFadeInFixedTime("Shot", 0.1f);
     muzzleFlash.Play();
     PlayShootSound();

     currentBullets--;
     fireTimer = 0.0f;
 }

 public void Reload()
 {
     if (bulletsLeft <= 0) return;

     int bulletsToLoad = bulletsPerMag - currentBullets;
     int bulletsToDeduct = (bulletsLeft >= bulletsToLoad) ? bulletsToLoad : bulletsLeft;

     bulletsLeft -= bulletsToDeduct;
     currentBullets += bulletsToDeduct;
 }

 private void DoReload()
 {
     AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(0);

     if (isReloading) return;

     anim.CrossFadeInFixedTime("Reload", 0.01f);

     audioSource.PlayOneShot(reloadSound);

 }

 private void PlayShootSound()
 {
     audioSource.PlayOneShot(shotSound);
 }

this weapon system script;

and this connect system script;

public static MaxPlayers m_InstanceMax = null; public static ModParty m_InstanceMod = null; public GameObject Room; public Transform[] spawnPoints;

 public GameObject myPlayer;

 [HideInInspector]
 public bool connect = false;

 [HideInInspector]
 public int ModParty;

 private byte Version = 1;
 public int PlayerMax = 10;

 /// <summary>if we don't want to connect in Start(), we have to "remember" if we called ConnectUsingSettings()</summary>
 private bool ConnectInUpdate = true;
 private bool Roomcreate = true;


 void Awake()
 {
     DontDestroyOnLoad(gameObject.transform);
 }

 void Start()
 {
     PhotonNetwork.autoJoinLobby = false;    // we join randomly. always. no need to join a lobby to get the list of rooms.
     

     SceneManager.sceneLoaded += (scene, loadscene) =>
     {
         if (SceneManager.GetActiveScene().name == "Game")
         {
             Spawn();
             
         }
     };
 }

 public void Spawn()
 {
     int index = UnityEngine.Random.Range(0, spawnPoints.Length);
     myPlayer = PhotonNetwork.Instantiate("Player", spawnPoints[index].position, spawnPoints[index].rotation, 0);
     myPlayer.transform.Find("MainCamera").gameObject.SetActive(true);
     ((MonoBehaviour)myPlayer.GetComponent("KarakterKontrol")).enabled = true;
 }

 public virtual void Update()
 {
     if (ConnectInUpdate && connect && !PhotonNetwork.connected)
     {
         Debug.Log("Update() was called by Unity. Scene is loaded. Let's connect to the Photon Master Server. Calling: PhotonNetwork.ConnectUsingSettings();");

         ConnectInUpdate = false;
         PhotonNetwork.ConnectUsingSettings(Version + "." + SceneManagerHelper.ActiveSceneBuildIndex);
     }
 }


 // below, we implement some callbacks of PUN
 // you can find PUN's callbacks in the class PunBehaviour or in enum PhotonNetworkingMessage


 public virtual void OnConnectedToMaster()
 {
     Debug.Log("Cherche party en mode : "+ModParty);

     ExitGames.Client.Photon.Hashtable expectedProperties = new ExitGames.Client.Photon.Hashtable();
     expectedProperties.Add( RoomProperty.Type, ModParty.ToString());

     PhotonNetwork.JoinRandomRoom( expectedProperties, 0 );
 }

 public virtual void OnPhotonRandomJoinFailed()
 {
     Debug.Log("Aucune party, on en crée une.");
     RoomOptions roomOptions = new RoomOptions();
     roomOptions.maxPlayers = (byte)PlayerMax;
     roomOptions.customRoomProperties = new ExitGames.Client.Photon.Hashtable();
     roomOptions.customRoomProperties.Add( RoomProperty.Map, "Test" );
     roomOptions.customRoomProperties.Add( RoomProperty.Type, ModParty.ToString() );
     roomOptions.customRoomPropertiesForLobby = new string[] {
         RoomProperty.Map,
         RoomProperty.Type,
     };

     PhotonNetwork.CreateRoom ("TestMap" + "@" + Guid.NewGuid().ToString("N"), roomOptions, null);

     Roomcreate = true;
 }

 public void OnJoinedRoom()
 {
     Debug.Log("In Room");
     AutoFade.m_Instance.BeginFade (-1);
     Room.SetActive (true);
     Room.GetComponent<ManageListMembers> ().PlayerMax = PlayerMax;
     this.gameObject.SetActive (false);
     PhotonNetwork.playerName = ClickMenuMain.m_InstancePseudo.pseudo;
     m_InstanceMax = (new GameObject("maxplayers")).AddComponent<MaxPlayers>();
     m_InstanceMod = (new GameObject("modparty")).AddComponent<ModParty>();
     m_InstanceMax.maxplayers = PlayerMax;
     m_InstanceMod.modparty = ModParty;
 }
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

115 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

Related Questions

Photon Player Weapon View Error Help Please 1 Answer

Photon Weapon synchronize View Help Please 0 Answers

Weapons Names And Models Licensing 1 Answer

How can you do borderlands style random weapons and stat generation? 2 Answers

I need Drop Weapon Scripe 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