Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerController : MonoBehaviour
- {
- public bool isMelee = false;
- public bool isRanged = true;
- public bool canAttack = true;
- public int meleeWeaponRange = 180;
- public float projectileSpeed = 500.0f;
- public float primaryCooldownTimer = 1.5f;
- public float primaryCooldownDefault = 1.5f;
- public int basicMeleeDamage = 15;
- public int basicRangedDamage = 10;
- public int ultimateBaseDamage = 60;
- public int healthPoints = 100;
- void Awake()
- {
- }
- // Use this for initialization
- void Start()
- {
- }
- // Update is called once per frame
- void Update()
- {
- if (Input.GetMouseButtonDown(0))
- {
- if (canAttack)
- {
- Debug.Log("I Can Attack!!");
- if (isMelee)
- {
- BasicMeleeAttack();
- }
- else
- {
- BasicRangedAttack();
- }
- }
- else
- {
- canAttack = false;
- Debug.Log("Cannot Attack Right Now");
- }
- }
- if (!canAttack)
- {
- primaryCooldownTimer -= Time.deltaTime;
- if (primaryCooldownTimer <= 0)
- {
- canAttack = true;
- primaryCooldownTimer = primaryCooldownDefault;
- }
- }
- }
- void BasicRangedAttack()
- {
- GameObject ball = (GameObject)GameObject.Instantiate(Resources.Load("TennisBall"));
- GameObject spawner = (GameObject)gameObject.transform.GetChild(0).GetChild(0).gameObject;
- ball.transform.position = spawner.transform.position;
- ball.GetComponent<Rigidbody>().AddForce(spawner.transform.forward * projectileSpeed);
- ball.GetComponent<TennisBall>().firedBy = this.gameObject;
- Destroy(ball.gameObject, 2.0f);
- canAttack = false;
- }
- void BasicMeleeAttack()
- {
- // Basic Melee Attack
- GameObject hands = (GameObject)gameObject.transform.GetChild(1).gameObject;
- Vector3 swingPos = hands.transform.position;
- Collider[] colliders = Physics.OverlapSphere(swingPos, meleeWeaponRange / 100);
- foreach (Collider hit in colliders)
- {
- // If player hit is on opposite team take relevant health points away from them
- if (hit.gameObject.tag == "Away")
- {
- //BasicDamage ();
- }
- }
- canAttack = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement