void HandleOnKeyPress_Right() { // Debug.Log ("Get Axis Right"); // reverse as left, depend go up or down by stair facing if (stairManager.isOnStair()) { if (stairManager.getCurStairFacing() == Globals.STAIR_FACING.Right) { stairManager.tryGoUpStair(); } else { stairManager.tryGoDownStair(); } return; } if (!grounded || whipAttManager.attacking || animator.GetBool("Squat")) { return; } if (curHorizontalVelocity == 0) { animator.SetInteger("Speed", 1); } else if (curHorizontalVelocity == 1) { ; } else if (curHorizontalVelocity == -1) { animator.SetInteger("Speed", 0); } else { Debug.LogError("Speed of a value different to 1,-1,0; Speed: " + curHorizontalVelocity); } }
void OnTriggerEnter2D(Collider2D coll) { Debug.Log("collided"); GameObject collidedObj = coll.gameObject; // get the four corner points of both object Vector2 objLL = collidedObj.collider2D.bounds.min; Vector2 objUR = collidedObj.collider2D.bounds.max; Vector2 myLL = collider2D.bounds.min; Vector2 myUR = collider2D.bounds.max; List <float> collDepth = new List <float> ( new float[4] { float.MaxValue, float.MaxValue, float.MaxValue, float.MaxValue }); // if(objUR.x >= myLL.x && objLL.x <= myLL.x) // Player on left collDepth[0] = objUR.x - myLL.x; // if(objLL.x <= myUR.x && objUR.x >= myUR.x) // Player on Right collDepth[1] = myUR.x - objLL.x; // if(objUR.y>= myLL.y && objLL.y <= myLL.y) // Player on Bottom collDepth[2] = objUR.y - myLL.y; // if(objLL.y <= myUR.y && objUR.y>= myUR.y) // Player on Top collDepth[3] = myUR.y - objLL.y - 0.02f; // return the closest intersection collIndex = collDepth.IndexOf(Mathf.Min(collDepth.ToArray())); CollisionManager cmScript = collidedObj.GetComponent <CollisionManager>(); if (cmScript != null) { if (collidedObj.tag == Globals.playerTag) { StairManager smScript = collidedObj.GetComponent <StairManager>(); if (smScript && smScript.isOnStair()) { collIndex = 3; } } cmScript.playerCollisionEnter(collIndex, this.gameObject.collider2D.bounds.max.y); collIdTable.Add(collidedObj.GetInstanceID(), collIndex); } }
// ============================================================================ // public IEnumerator Hurt() { status.playerHealth -= 2; if (stairMan.isOnStair()) { hurting = true; StartCoroutine(turnInvisible()); yield return(null); } else { Debug.Log("HURTING: Hurt fucntion called"); hurting = true; // TODO do what ever is needed to turn off some collision // CODE HERE disableControl = true; animator.SetBool("Hurt", true); pc.VerticalSpeed = 0; //reset to avoid fly high pc.VerticalSpeed += initHurtVericalSpeed; // add horizontal speed according to facing pc.CurHorizontalVelocity = pc.facingRight? -1 : 1; yield return(new WaitForSeconds(0.33f)); animator.SetBool("Hurt", false); Debug.Log("HURTING: fly state cleaned"); StartCoroutine(turnInvisible()); // turn animator.SetInteger("Speed", 0); yield return(new WaitForSeconds(0f)); pc.CurHorizontalVelocity = 0; disableControl = false; } }
void OnTriggerStay2D(Collider2D coll) { GameObject collObj = coll.gameObject; Debug.Log("ready to change scene on stair" + collObj.tag); if (collObj.tag == Globals.playerTag) { PlayerController plScript = collObj.GetComponent <PlayerController>(); StairManager smScript = collObj.GetComponent <StairManager>(); StatusManager stScript = collObj.GetComponent <StatusManager>(); if (smScript.isOnStair()) { if ((targetScene.Equals("Scene_01") && plScript.facingRight == false) || (targetScene.Equals("Scene_02") && plScript.facingRight == true)) { Debug.Log("changed to " + targetScene + " on stair"); stScript.portalNum = thisPortalNum; stScript.enterStairPortal(targetScene); } } } }