Guest User

Untitled

a guest
Jul 21st, 2017
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Character Controll;
  2.  
  3. public float hareketHizi;
  4.  public float ziplama;
  5.  public GameObject kamera;
  6.  public GameObject kapsul;
  7.  public float kameraAcisi;
  8.  void Start () {
  9.  }
  10.  
  11.  void Update () {
  12.      KarakterHareket();
  13.      KameraKontrol();
  14.  }
  15.  void KameraKontrol()
  16.  {
  17.      float x = Input.GetAxis("Mouse X");
  18.      float y = Input.GetAxis("Mouse Y");
  19.      kapsul.transform.Rotate(new Vector3(0, 1, 0) * x);
  20.      kameraAcisi -= y;
  21.      kameraAcisi = Mathf.Clamp(kameraAcisi, -90, 90);
  22.      kamera.transform.localEulerAngles = new Vector3(kameraAcisi, 0, 0);
  23.  }
  24.  void KarakterHareket()
  25.  {
  26.      float v = Input.GetAxis("Vertical");
  27.      float h = Input.GetAxis("Horizontal");
  28.      Vector3 yon = Vector3.Normalize(new Vector3(h, 0, v));
  29.      transform.Translate(yon * hareketHizi * Time.deltaTime);
  30.      
  31.      if (Input.GetKeyDown(KeyCode.LeftShift))
  32.      {
  33.          hareketHizi = 8;
  34.      }
  35.      if (Input.GetKeyUp(KeyCode.LeftShift))
  36.      {
  37.          hareketHizi = 5;
  38.      }
  39.      RaycastHit ray;
  40.      Physics.Raycast(transform.position, Vector3.down, out ray, Mathf.Infinity);
  41.      if(ray.distance < 1.2f)
  42.      {
  43.          if (Input.GetKeyDown(KeyCode.Space))
  44.          {
  45.              GetComponent<Rigidbody>().AddForce(Vector3.up * ziplama);
  46.          }
  47.      }
  48.  }
  49.  
  50.  
  51. Connect Manager;
  52.  
  53. public static MaxPlayers m_InstanceMax = null;
  54.  public static ModParty m_InstanceMod = null;
  55.  public GameObject Room;
  56.  public Transform[] spawnPoints;
  57.  public GameObject myPlayer;
  58.  [HideInInspector]
  59.  public bool connect = false;
  60.  [HideInInspector]
  61.  public int ModParty;
  62.  private byte Version = 1;
  63.  public int PlayerMax = 10;
  64.  /// <summary>if we don't want to connect in Start(), we have to "remember" if we called ConnectUsingSettings()</summary>
  65.  private bool ConnectInUpdate = true;
  66.  private bool Roomcreate = true;
  67.  void Awake()
  68.  {
  69.      DontDestroyOnLoad(gameObject.transform);
  70.  }
  71.  void Start()
  72.  {
  73.      PhotonNetwork.autoJoinLobby = false;    // we join randomly. always. no need to join a lobby to get the list of rooms.
  74.      
  75.      SceneManager.sceneLoaded += (scene, loadscene) =>
  76.      {
  77.          if (SceneManager.GetActiveScene().name == "Game")
  78.          {
  79.              Spawn();
  80.          }
  81.      };
  82.  }
  83.  public virtual void Update()
  84.  {
  85.      if (ConnectInUpdate && connect && !PhotonNetwork.connected)
  86.      {
  87.          Debug.Log("Update() was called by Unity. Scene is loaded. Let's connect to the Photon Master Server. Calling: PhotonNetwork.ConnectUsingSettings();");
  88.          ConnectInUpdate = false;
  89.          PhotonNetwork.ConnectUsingSettings(Version + "." + SceneManagerHelper.ActiveSceneBuildIndex);
  90.      }
  91.  }
  92.  public void Spawn()
  93.  {
  94.      int index = UnityEngine.Random.Range(0, spawnPoints.Length);
  95.      myPlayer = PhotonNetwork.Instantiate("Player", spawnPoints[index].position, spawnPoints[index].rotation, 0);
  96.  }
  97.  // below, we implement some callbacks of PUN
  98.  // you can find PUN's callbacks in the class PunBehaviour or in enum PhotonNetworkingMessage
  99.  public virtual void OnConnectedToMaster()
  100.  {
  101.      Debug.Log("Cherche party en mode : "+ModParty);
  102.      ExitGames.Client.Photon.Hashtable expectedProperties = new ExitGames.Client.Photon.Hashtable();
  103.      expectedProperties.Add( RoomProperty.Type, ModParty.ToString());
  104.      PhotonNetwork.JoinRandomRoom( expectedProperties, 0 );
  105.  }
  106.  public virtual void OnPhotonRandomJoinFailed()
  107.  {
  108.      Debug.Log("Aucune party, on en crée une.");
  109.      RoomOptions roomOptions = new RoomOptions();
  110.      roomOptions.maxPlayers = (byte)PlayerMax;
  111.      roomOptions.customRoomProperties = new ExitGames.Client.Photon.Hashtable();
  112.      roomOptions.customRoomProperties.Add( RoomProperty.Map, "Test" );
  113.      roomOptions.customRoomProperties.Add( RoomProperty.Type, ModParty.ToString() );
  114.      roomOptions.customRoomPropertiesForLobby = new string[] {
  115.          RoomProperty.Map,
  116.          RoomProperty.Type,
  117.      };
  118.      PhotonNetwork.CreateRoom ("TestMap" + "@" + Guid.NewGuid().ToString("N"), roomOptions, null);
  119.      Roomcreate = true;
  120.  }
  121.  public void OnJoinedRoom()
  122.  {
  123.      Debug.Log("In Room");
  124.      AutoFade.m_Instance.BeginFade (-1);
  125.      Room.SetActive (true);
  126.      Room.GetComponent<ManageListMembers> ().PlayerMax = PlayerMax;
  127.      this.gameObject.SetActive (false);
  128.      PhotonNetwork.playerName = ClickMenuMain.m_InstancePseudo.pseudo;
  129.      m_InstanceMax = (new GameObject("maxplayers")).AddComponent<MaxPlayers>();
  130.      m_InstanceMod = (new GameObject("modparty")).AddComponent<ModParty>();
  131.      m_InstanceMax.maxplayers = PlayerMax;
  132.      m_InstanceMod.modparty = ModParty;
  133.  }
  134.  
  135.  
  136. Weapon;
  137.  
  138.    private Animator anim;
  139.     private AudioSource audioSource;
  140.  
  141.     public float range = 100f;
  142.     public int bulletsPerMag = 30;
  143.     public int bulletsLeft = 200;
  144.     public int currentBullets;
  145.  
  146.     public enum ShootMode {Auto,Semi }
  147.     public ShootMode shootingMode;
  148.  
  149.     public Transform shootPoint;
  150.     public ParticleSystem muzzleFlash;
  151.     public AudioClip shotSound;
  152.     public AudioClip reloadSound;
  153.  
  154.     float damage = 20f;
  155.  
  156.     public GameObject hitParticles;
  157.     public GameObject bulletImpact;
  158.  
  159.     public float fireRate = 0.08f;
  160.     float fireTimer;
  161.  
  162.     private bool isReloading;
  163.     private bool shootInput;
  164.     private bool isAiming;
  165.  
  166.     private Vector3 originalPosition;
  167.     public Vector3 aimPosition;
  168.     public float aodSpeed;
  169.  
  170.     public float maxBulletSpreadAngle = 15.0f;
  171.  
  172.     void Start () {
  173.         anim = GetComponent<Animator>();
  174.  
  175.         audioSource = GetComponent<AudioSource>();
  176.  
  177.         currentBullets = bulletsPerMag;
  178.  
  179.         originalPosition = transform.localPosition;
  180.     }
  181.  
  182.     void Update () {
  183.  
  184.         switch (shootingMode)
  185.         {
  186.             case ShootMode.Auto:
  187.                 shootInput = Input.GetButton("Fire1");
  188.                 break;
  189.  
  190.             case ShootMode.Semi:
  191.                 shootInput = Input.GetButtonDown("Fire1");
  192.                 break;
  193.         }
  194.  
  195.         if (shootInput)
  196.         {
  197.             if (currentBullets > 0)
  198.             {
  199.                 Fire();
  200.             }
  201.             else if(bulletsLeft > 0 )
  202.             {
  203.                 DoReload();
  204.             }  
  205.         }
  206.  
  207.         if (Input.GetKeyDown(KeyCode.R))
  208.         {
  209.             if (currentBullets < bulletsPerMag && bulletsLeft > 0)
  210.                 DoReload();
  211.         }
  212.  
  213.         if (fireTimer < fireRate)
  214.             fireTimer += Time.deltaTime;
  215.  
  216.         AimDownSights();
  217.     }
  218.  
  219.     private void AimDownSights()
  220.     {
  221.         if (Input.GetButton("Fire2"))
  222.         {
  223.             transform.localPosition = Vector3.Lerp(transform.localPosition, aimPosition, Time.deltaTime * aodSpeed);
  224.             isAiming = true;
  225.         }
  226.         else
  227.         {
  228.             transform.localPosition = Vector3.Lerp(transform.localPosition, originalPosition, Time.deltaTime * aodSpeed);
  229.             isAiming = false;
  230.         }
  231.     }
  232.  
  233.     void FixedUpdate()
  234.     {
  235.         AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(0);
  236.  
  237.         isReloading = info.IsName("Reload");
  238.  
  239.         anim.SetBool("Aim", isAiming);
  240.         //if (info.IsName("Shot")) anim.SetBool("Shot", false);
  241.     }
  242.  
  243.     public void Fire()
  244.     {
  245.         if (fireTimer < fireRate || currentBullets <= 0 || isReloading) return;
  246.  
  247.         RaycastHit hit;
  248.        
  249.         Vector3 fireDirection = shootPoint.transform.forward;
  250.  
  251.         Quaternion fireRotation = Quaternion.LookRotation(fireDirection);
  252.  
  253.         Quaternion randomRotation = Random.rotation;
  254.  
  255.         fireRotation = Quaternion.RotateTowards(fireRotation, randomRotation, Random.Range(0.0f, maxBulletSpreadAngle));
  256.  
  257.         if (Physics.Raycast(shootPoint.position, fireRotation * Vector3.forward, out hit, range))
  258.         {
  259.             Health h = hit.transform.GetComponentInParent<Health>();
  260.  
  261.             if(h != null)
  262.             {
  263.                 h.GetComponent<PhotonView>().RPC("TakeDamage", PhotonTargets.AllBuffered, damage);
  264.             }
  265.  
  266.             Debug.Log(hit.transform.name + "found!");
  267.  
  268.             GameObject hitParticleEffect = Instantiate(hitParticles, hit.point, Quaternion.FromToRotation(Vector3.up, hit.normal));
  269.             GameObject bulletHole = Instantiate(bulletImpact, hit.point, Quaternion.FromToRotation(Vector3.forward, hit.normal));
  270.  
  271.             Destroy(hitParticleEffect, 1f);
  272.             Destroy(bulletHole, 2f);
  273.            
  274.  
  275.         }
  276.         anim.CrossFadeInFixedTime("Shot", 0.1f);
  277.         muzzleFlash.Play();
  278.         PlayShootSound();
  279.  
  280.         currentBullets--;
  281.         fireTimer = 0.0f;
  282.     }
  283.  
  284.     public void Reload()
  285.     {
  286.         if (bulletsLeft <= 0) return;
  287.  
  288.         int bulletsToLoad = bulletsPerMag - currentBullets;
  289.         int bulletsToDeduct = (bulletsLeft >= bulletsToLoad) ? bulletsToLoad : bulletsLeft;
  290.  
  291.         bulletsLeft -= bulletsToDeduct;
  292.         currentBullets += bulletsToDeduct;
  293.     }
  294.  
  295.     private void DoReload()
  296.     {
  297.         AnimatorStateInfo info = anim.GetCurrentAnimatorStateInfo(0);
  298.  
  299.         if (isReloading) return;
  300.  
  301.         anim.CrossFadeInFixedTime("Reload", 0.01f);
  302.  
  303.         audioSource.PlayOneShot(reloadSound);
  304.  
  305.     }
  306.  
  307.     private void PlayShootSound()
  308.     {
  309.         audioSource.PlayOneShot(shotSound);
  310.     }
  311. }
RAW Paste Data