Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.64 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlayerController : MonoBehaviour
  6. {
  7.  
  8.     public bool isMelee = false;
  9.     public bool isRanged = true;
  10.     public bool canAttack = true;
  11.     public int meleeWeaponRange = 180;
  12.     public float projectileSpeed = 500.0f;
  13.     public float primaryCooldownTimer = 1.5f;
  14.     public float primaryCooldownDefault = 1.5f;
  15.     public int basicMeleeDamage = 15;
  16.     public int basicRangedDamage = 10;
  17.     public int ultimateBaseDamage = 60;
  18.     public int healthPoints = 100;
  19.  
  20.     void Awake()
  21.     {
  22.  
  23.  
  24.  
  25.     }
  26.  
  27.     // Use this for initialization
  28.     void Start()
  29.     {
  30.  
  31.  
  32.  
  33.     }
  34.  
  35.     // Update is called once per frame
  36.     void Update()
  37.     {
  38.  
  39.         if (Input.GetMouseButtonDown(0))
  40.         {
  41.             if (canAttack)
  42.             {
  43.                 Debug.Log("I Can Attack!!");
  44.  
  45.                 if (isMelee)
  46.                 {
  47.                     BasicMeleeAttack();
  48.                 }
  49.                 else
  50.                 {
  51.                     BasicRangedAttack();
  52.                 }
  53.  
  54.             }
  55.             else
  56.             {
  57.                 canAttack = false;
  58.                 Debug.Log("Cannot Attack Right Now");
  59.             }
  60.         }
  61.  
  62.         if (!canAttack)
  63.         {
  64.             primaryCooldownTimer -= Time.deltaTime;
  65.             if (primaryCooldownTimer <= 0)
  66.             {
  67.                 canAttack = true;
  68.                 primaryCooldownTimer = primaryCooldownDefault;
  69.             }
  70.  
  71.         }
  72.     }
  73.  
  74.     void BasicRangedAttack()
  75.     {
  76.         GameObject ball = (GameObject)GameObject.Instantiate(Resources.Load("TennisBall"));
  77.         GameObject spawner = (GameObject)gameObject.transform.GetChild(0).GetChild(0).gameObject;
  78.         ball.transform.position = spawner.transform.position;
  79.         ball.GetComponent<Rigidbody>().AddForce(spawner.transform.forward * projectileSpeed);
  80.         ball.GetComponent<TennisBall>().firedBy = this.gameObject;
  81.         Destroy(ball.gameObject, 2.0f);
  82.         canAttack = false;
  83.     }
  84.  
  85.     void BasicMeleeAttack()
  86.     {
  87.         // Basic Melee Attack
  88.         GameObject hands = (GameObject)gameObject.transform.GetChild(1).gameObject;
  89.         Vector3 swingPos = hands.transform.position;
  90.         Collider[] colliders = Physics.OverlapSphere(swingPos, meleeWeaponRange / 100);
  91.         foreach (Collider hit in colliders)
  92.         {
  93.             // If player hit is on opposite team take relevant health points away from them
  94.             if (hit.gameObject.tag == "Away")
  95.             {
  96.                 //BasicDamage ();
  97.             }
  98.         }
  99.         canAttack = false;
  100.     }
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement