Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.69 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5.  
  6. public class SetupLocalPlayer : NetworkBehaviour {
  7.  
  8.     Quaternion rotation;
  9.     Rigidbody rb;
  10.     NetworkAnimator anim;
  11.  
  12.     public float speed = 0.1f;
  13.     public float startTimeBtwAttack = 2;
  14.     public float startTImeBtwAttack3;
  15.     public float startTimeBtwAttack4;
  16.     public float sphereRadius = 5f;
  17.     public float cleaveDamage = 10f;
  18.     public float whirlwindDamage = 20f;
  19.     public float hamstringDamage = 5f;
  20.  
  21.     [SyncVar]
  22.     private float dmgAmount;
  23.  
  24.  
  25.     private float timeBtwAttack;
  26.     private float timeBtwAttack3;
  27.     private float timeBtwAttack4;
  28.     private float speedTimer;
  29.  
  30.  
  31.     // Use this for initialization
  32.     void Start () {
  33.  
  34.         anim = GetComponentInChildren<NetworkAnimator>();
  35.  
  36.         if (isLocalPlayer)
  37.         {
  38.             GetComponent<BobControls>().enabled = true;
  39.             WowCamera.target = this.gameObject.transform;
  40.         }
  41.         else
  42.         {
  43.             GetComponent<BobControls>().enabled = false;
  44.         }
  45.  
  46.     }
  47.    
  48.     // Update is called once per frame
  49.     void Update () {
  50.         CheckAbilityOne();
  51.         CheckAbilityTwo();
  52.         CheckAbilityFour();
  53.     }
  54.  
  55.     [Command]
  56.     public void CmdUpdateHealth(float health)
  57.     {
  58.         UpdateHealth(health);
  59.     }
  60.  
  61.     void UpdateHealth(float hp)
  62.     {
  63.         Debug.Log("hersky fersky new hp " + hp);
  64.     }
  65.  
  66.     private void CheckAbilityOne()
  67.     {
  68.         if (timeBtwAttack <= 0)
  69.         {
  70.             if (Input.GetKeyDown(KeyCode.Alpha1))
  71.             {
  72.                 timeBtwAttack = startTimeBtwAttack;
  73.                 anim.SetTrigger("Cleave");
  74.                 dmgAmount = cleaveDamage;
  75.  
  76.                 Collider[] hits = Physics.OverlapSphere(transform.position, sphereRadius);
  77.                
  78.  
  79.                 foreach (Collider hit in hits)
  80.                 {
  81.  
  82.                    
  83.                     if (!isLocalPlayer)
  84.                     {
  85.                         Debug.Log(hit.name);
  86.                         if (hit.tag == "Player")
  87.                         {
  88.                             print("hit " + hit.gameObject);   // <-----------------
  89.                             Damage(hit.transform);
  90.                         }
  91.                     }
  92.                    
  93.                 }
  94.             }
  95.         }    
  96.     }
  97.  
  98.     private void CheckAbilityTwo()
  99.     {
  100.         if (Input.GetKeyDown(KeyCode.Alpha2))
  101.         {
  102.             anim.SetTrigger("Hamstring");
  103.         }
  104.     }
  105.  
  106.  
  107.     private void CheckAbilityFour()
  108.     {
  109.         //if (timeBtwAttack4 <= 0)
  110.         //{
  111.         //    if (Input.GetKeyDown(KeyCode.Alpha4))
  112.         //    {
  113.  
  114.         //        timeBtwAttack4 = startTimeBtwAttack4;
  115.         //        anim.SetTrigger("Whirlwind");
  116.         //        dmgAmount = whirlwindDamage;
  117.  
  118.         //        Collider[] hits = Physics.OverlapSphere(transform.position, sphereRadius);
  119.                
  120.         //        foreach (Collider hit in hits)
  121.         //        {
  122.                    
  123.         //            if (hit.tag == "Player")
  124.         //            {
  125.         //                print("hit " + hit.gameObject);
  126.         //                Damage(hit.transform);
  127.         //            }
  128.         //        }
  129.  
  130.         //    }
  131.         //}
  132.         //else
  133.         //{
  134.         //    timeBtwAttack4 -= Time.deltaTime;
  135.         //}
  136.     }
  137.  
  138.  
  139.     void Damage(Transform enemy)
  140.     {
  141.         Enemy e = enemy.GetComponent<Enemy>();
  142.  
  143.         if (e != null)
  144.         {
  145.             e.TakeDamage(dmgAmount);
  146.         }
  147.         else
  148.         {
  149.             Debug.Log("Error taking damage.");
  150.         }
  151.  
  152.  
  153.     }
  154.  
  155.  
  156.  
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement