Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- public class WeaponSystem : MonoBehaviour {
- public int TheDamage1;
- public int TheDamage2;
- public float Distance;
- public float MaxDistance;
- public Animator TheAnimator;
- public float DammageDelay;
- public int Hit01Streak;
- public int Hit02Streak;
- public AudioClip[] HitWood;
- public AudioClip[] HitConcrete;
- public AudioClip[] HitMetal;
- public AudioClip[] HitGlass;
- public AudioClip[] HitEnemy;
- public AudioClip[] HitDirt;
- public AudioClip[] Swing;
- public GameObject woodFX;
- public GameObject concreteFX;
- public GameObject glassFX;
- public GameObject metalFX;
- public GameObject bloodFX;
- public GameObject dirtFX;
- public GameObject decal;
- public GameObject decalGlass;
- public float addpos;
- public bool canhit;
- public float attackTimer;
- public float coolDown;
- public float Durability;
- public float MaxDurability;
- public float MinusDur1;
- public float MinusDur2;
- public bool havewalk;
- static public bool canharvestwood;
- public bool canharvestwood2;
- static public bool canharveststone;
- public bool canharveststone2;
- public GameObject wood;
- // Update is called once per frame
- void Update () {
- canharvestwood = canharvestwood2;
- canharveststone = canharveststone2;
- if (Durability >= MaxDurability) {
- Durability = MaxDurability;
- }
- if (Durability <= 0) {
- Durability = 0;
- }
- if (Durability <= 0) {
- Destroy (gameObject);
- }
- if (attackTimer > 0)
- attackTimer -= Time.deltaTime;
- if (attackTimer < 0)
- attackTimer = 0;
- if (Input.GetButtonDown ("Fire1")) {
- if (attackTimer == 0) {
- AttackDammage ();
- AttackSound ();
- print ("Hit");
- attackTimer = coolDown;
- }
- }
- }
- void AttackSound () {
- audio.clip = (Swing[Random.Range(0,Swing.Length)]);
- audio.Play();
- }
- IEnumerator AttackDammage() {
- if(Random.value >= 0.5 && Hit01Streak <=2)
- {
- TheAnimator.SetBool("Hit01", true);
- Hit01Streak += 1;
- Hit02Streak = 0;
- }
- else
- {
- if (Hit02Streak <= 2)
- {
- TheAnimator.SetBool("Hit02",true);
- Hit01Streak = 0;
- Hit02Streak += 1;
- }
- else
- {
- TheAnimator.SetBool("Hit01", true);
- Hit01Streak +=1;
- Hit02Streak = 0;
- }
- }
- yield return new WaitForSeconds(DammageDelay);
- //actual attack
- RaycastHit hit;
- var ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width/2, Screen.height/2, 0));
- if(Physics.Raycast(ray, out hit))
- {
- Distance = hit.distance;
- if(Distance < MaxDistance)
- {
- //var hitRotation = Quaternion.Euler( Random.Range(0, 360) , 0 , 0); //not working
- Quaternion hitRotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
- if(hit.transform.gameObject.tag == "Wood") {
- Instantiate(woodFX, hit.point, hitRotation);
- audio.clip = (HitWood[Random.Range(0,HitWood.Length)]);
- audio.Play();
- Instantiate(decal, hit.point + (hit.normal * addpos), hitRotation);
- }
- if(hit.transform.gameObject.tag == "Concrete") {
- Instantiate(concreteFX, hit.point, hitRotation);
- audio.clip = (HitConcrete[Random.Range(0,HitConcrete.Length)]);
- audio.Play();
- Instantiate(decal, hit.point + (hit.normal * addpos), hitRotation);
- }
- if(hit.transform.gameObject.tag == "Glass") {
- Instantiate(glassFX, hit.point, hitRotation);
- audio.clip = (HitGlass[Random.Range(0,HitGlass.Length)]);
- audio.Play();
- Instantiate(decalGlass, hit.point + (hit.normal * addpos), hitRotation);
- }
- if(hit.transform.gameObject.tag == "Dirt") {
- Instantiate(dirtFX, hit.point + (hit.normal * addpos), hitRotation);
- Instantiate(dirtFX, hit.point, hitRotation);
- audio.clip = (HitDirt[Random.Range(0,HitDirt.Length)]);
- audio.Play();
- Instantiate(decal, hit.point + (hit.normal * addpos), hitRotation);
- }
- if(hit.transform.gameObject.tag == "Metal") {
- Instantiate(metalFX, hit.point, hitRotation);
- audio.clip = (HitMetal[Random.Range(0,HitMetal.Length)]);
- audio.Play();
- Instantiate(decal, hit.point + (hit.normal * addpos), hitRotation);
- }
- if(hit.transform.gameObject.tag == "Enemy") {
- Instantiate(bloodFX, hit.point, hitRotation);
- audio.clip = (HitEnemy[Random.Range(0,HitEnemy.Length)]);
- audio.Play();
- Instantiate(decal, hit.point + (hit.normal * addpos), hitRotation);
- }
- hit.transform.SendMessage("ApplyTheDammage", Random.Range(TheDamage1,TheDamage2) , SendMessageOptions.DontRequireReceiver);
- // var blood = Instantiate(bloodFX, transform.position, Quaternion.identity);
- Durability -= Random.Range(MinusDur1,MinusDur2);
- }
- }
- TheAnimator.SetBool("Hit01", false);
- TheAnimator.SetBool("Hit02", false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement