赞
踩
- using UnityEngine;
- namespace QuickStart
- {
- public class SceneReference : MonoBehaviour
- {
- public SceneScript sceneScript;
- }
- }
- using UnityEngine.SceneManagement;
- public void ButtonChangeScene()
- {
- if (isServer)
- {
- Scene scene = SceneManager.GetActiveScene();
- if (scene.name == "MainScene") { NetworkManager.singleton.ServerChangeScene("MyOtherScene"); }
- else { NetworkManager.singleton.ServerChangeScene("MainScene"); }
- }
- else { Debug.Log("You are not Host."); }
- }
- using UnityEngine;
- using UnityEngine.SceneManagement;
- namespace QuickStart
- {
- public class Menu : MonoBehaviour
- {
- public void LoadScene()
- {
- SceneManager.LoadScene("GamesList");
- }
- }
- }
- using UnityEngine;
- using UnityEngine.SceneManagement;
- namespace QuickStart
- {
- public class GamesList : MonoBehaviour
- {
- public void LoadScene()
- {
- SceneManager.LoadScene("Menu");
- }
- }
- }
- using UnityEngine;
- namespace QuickStart
- {
- public class Weapon : MonoBehaviour
- {
- public float weaponSpeed = 15.0f;
- public float weaponLife = 3.0f;
- public float weaponCooldown = 1.0f;
- public int weaponAmmo = 15;
- public GameObject weaponBullet;
- public Transform weaponFirePosition;
- }
- }
- public Text canvasAmmoText;
-
- public void UIAmmo(int _value)
- {
- canvasAmmoText.text = "Ammo: " + _value;
- }
- private Weapon activeWeapon;
- private float weaponCooldownTime;
- void OnWeaponChanged(int _Old, int _New)
- {
- // disable old weapon
- // in range and not null
- if (0 < _Old && _Old < weaponArray.Length && weaponArray[_Old] != null)
- {
- weaponArray[_Old].SetActive(false);
- }
-
- // enable new weapon
- // in range and not null
- if (0 < _New && _New < weaponArray.Length && weaponArray[_New] != null)
- {
- weaponArray[_New].SetActive(true);
- activeWeapon = weaponArray[activeWeaponSynced].GetComponent<Weapon>();
- if( isLocalPlayer ) { sceneScript.UIAmmo(activeWeapon.weaponAmmo); }
- }
- }
- if (selectedWeaponLocal < weaponArray.Length && weaponArray[selectedWeaponLocal] != null)
- { activeWeapon = weaponArray[selectedWeaponLocal].GetComponent<Weapon>(); sceneScript.UIAmmo(activeWeapon.weaponAmmo); }
- if (Input.GetButtonDown("Fire1") ) //Fire1 is mouse 1st click
- {
- if (activeWeapon && Time.time > weaponCooldownTime && activeWeapon.weaponAmmo > 0)
- {
- weaponCooldownTime = Time.time + activeWeapon.weaponCooldown;
- activeWeapon.weaponAmmo -= 1;
- sceneScript.UIAmmo(activeWeapon.weaponAmmo);
- CmdShootRay();
- }
- }
- [Command]
- void CmdShootRay()
- {
- RpcFireWeapon();
- }
- [ClientRpc]
- void RpcFireWeapon()
- {
- //bulletAudio.Play(); muzzleflash etc
- var bullet = (GameObject)Instantiate(activeWeapon.weaponBullet, activeWeapon.weaponFirePosition.position, activeWeapon.weaponFirePosition.rotation);
- bullet.GetComponent<Rigidbody>().velocity = bullet.transform.forward * activeWeapon.weaponSpeed;
- if (bullet) { Destroy(bullet, activeWeapon.weaponLife); }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。