Quantcast
Channel: Questions in topic: "melee"
Viewing all articles
Browse latest Browse all 201

Measuring time between hits to apply COMBO ATTACK animations

$
0
0
![alt text][1] [1]: /storage/temp/60906-20151230-152648.png Hi. My simple game project is about running and breaking walls. I have PlayerCtrl script that manages player animations and WallCtrl script that detects hits. I'm using Animator.Setbool() to switch between animations I'm trying to apply different hitting animations only when a player hits walls continuously in short time(combo hits). I googled and they say measure time between hit and hit but I need little more advice. can anyone tell me how to measure time between two wall hits? and some tips about what to do after time measured would be very appreciated. here's PlayerCtrl script and WallCtrl script below. thank you so much for reading. public class PlayerCtrl : MonoBehaviour { public float moveSpeed; public float jumpForce; public bool isAttackDone = true; public GameObject hitCollider; public GameObject hitColliderPos; private Rigidbody2D myRigidbody2D; private Animator anim; // Use this for initialization void Start () { myRigidbody2D = GetComponent(); anim = GetComponent(); isAttackDone = true; } // Update is called once per frame void Update () { //Debug.Log ("isAttackDone = " + isAttackDone); myRigidbody2D.velocity = new Vector2(moveSpeed, myRigidbody2D.velocity.y); if (Input.GetKeyDown(KeyCode.Space) || Input.GetMouseButtonDown(0)) { if (isAttackDone == true) { GameObject hitColl = (GameObject) Instantiate (hitCollider, hitColliderPos.transform.position, hitColliderPos.transform.rotation); anim.SetBool("Attack", true); hitColl.transform.parent = GameObject.FindGameObjectWithTag("PLAYER").transform ; Debug.Log("PUNCH!!"); isAttackDone = false; } } } public void isAttackDoneTrue() { isAttackDone = true; anim.SetBool("Attack",false); } public void DestroyHitCollider() { Destroy (GameObject.FindGameObjectWithTag("HIT")); } public void Die() { anim.SetBool("Die", true); } } public class WallCtrl : MonoBehaviour { private BoxCollider2D wallCollider; private bool isGameOver = false; private Animator wallAnim; private UImgr uiMgr; private PlayerCtrl playerCtrl; private PlatformCtrl platformCtrl; // Use this for initialization void Start () { wallCollider = GetComponent(); wallAnim = GetComponent(); uiMgr = GameObject.FindGameObjectWithTag("CANVAS").GetComponent(); playerCtrl = GameObject.FindGameObjectWithTag("PLAYER").GetComponent(); platformCtrl = GameObject.FindGameObjectWithTag("PLATFORM").GetComponent(); } // Update is called once per frame void Update () { } void OnTriggerEnter2D (Collider2D other) { if (other.tag == "HIT") { if(isGameOver == false) { wallAnim.SetBool("Break", true); Debug.Log ("HIT!!!"); wallCollider.enabled = false; uiMgr.ScoreUp(); //Destroy (other.gameObject); } } } void OnCollisionEnter2D (Collision2D coll) { if (coll.collider.tag == "PLAYER") { isGameOver = true; playerCtrl.Die(); platformCtrl.moreWalls = false; Debug.Log("GAME OVER"); } } public void DestroyWall() { Destroy (this.gameObject); } }

Viewing all articles
Browse latest Browse all 201

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>