slimecing

a fighting game featuring slimes and swords
Log | Files | Refs | README

BlockScript.cs (2082B)


      1 using System.Collections;
      2 using System.Collections.Generic;
      3 using UnityEngine;
      4 
      5 public class BlockScript : MonoBehaviour {
      6 
      7     public float width = 5; //Width of the block hitbox
      8     public float blockSpeed = 5;
      9     public float blockTime = 1;
     10 
     11     private GameObject sword; //Parent sword
     12     private GameObject Owner; //Owner slime
     13     
     14     private SwordScript swordScript; //Parent's sword script
     15     private PlayerMovement playerMovement;
     16 
     17 	void Start ()
     18     {
     19         transform.localScale = new Vector3(width, 1.15f, 0.43f); //Sets the scale of the block hitbox
     20         sword = transform.parent.gameObject;
     21         Debug.Log(sword);
     22         swordScript = sword.GetComponent<SwordScript>();
     23         Owner = swordScript.Owner;
     24         playerMovement = Owner.GetComponent<PlayerMovement>();
     25 	}
     26 
     27     public void blockSword(GameObject otherSword)
     28     {
     29         sword = transform.parent.gameObject;
     30         SwordScript swordScript = sword.GetComponent<SwordScript>();
     31         Rigidbody swordRB = sword.gameObject.GetComponent<Rigidbody>();
     32         //Vector3 relativePoint = sword.transform.InverseTransformPoint(otherSword.transform.position);
     33         if(!swordScript.swordDone)
     34         {
     35             swordScript.stopCoroutines();
     36             playerMovement.stopCoroutines();
     37             playerMovement.currentSpeed = playerMovement.speed;
     38             playerMovement.thrustDebuff = false;
     39             swordScript.swordDone = true;
     40             swordRB.velocity = Vector3.zero;
     41             //Can move sword again set to position incase mouse position was changed during thrust
     42             swordScript.MoveSword();
     43             swordScript.isBlocked = false;
     44             swordScript.thrustHit = true;
     45         }
     46         else
     47         {
     48             swordScript.blockedOffset = sword.transform.position - swordScript.Owner.transform.position;
     49             StartCoroutine(Countdown(blockTime));
     50         }
     51     }
     52 
     53     private IEnumerator Countdown(float waitTime)
     54     {
     55         yield return new WaitForSeconds(waitTime);
     56         sword.GetComponent<SwordScript>().isBlocked = false;
     57     }
     58 
     59 }