//Initialize private void OnEnable() { interval = rightPos.position - leftPos.position; stairRenderer = stair.GetComponent <Renderer>(); stairLength = stairRenderer.bounds.size.x; //auto correct (the generated pos is always set to be the obj center, thus the edge need "reduce") rightPos.position = rightPos.position - interval.normalized * stairLength; leftPos.position = leftPos.position + interval.normalized * stairLength; //generate one at center when activated? //Instantiate(stair, leftPos.position + interval / 2, Quaternion.identity); lastGeneratePos = leftPos.position + interval / 2; if (gap <= 0) { needGapCheck = false; } if (attachTo != null) { needtoAttach = true; } if (FindObjectOfType <StairManager>() == null) { Debug.LogWarning("This scene lacks a object containing StairManager.cs, thus some funct. of the " + GetType().Name + ".cs won't work."); } else { theStairManager = FindObjectOfType <StairManager>(); } executable = true; }
void Start() { animator = GetComponent <Animator> (); pc = GetComponent <PlayerController> (); sprite = GetComponent <SpriteRenderer> (); status = GetComponent <StatusManager> (); stairMan = GetComponent <StairManager> (); hurting = false; disableControl = false; }
//Gets executed as soon as the game obejct is initialized private void Awake() { currentSprite = PlayerPrefs.GetInt("Sprite", 0); Debug.Log("The Current Sprite Index is:" + currentSprite); gameObject.GetComponent <SpriteRenderer>().sprite = theShopManager.sprites[currentSprite]; gameObject.SetActive(true); myRigidBody = GetComponent <Rigidbody2D>(); theStairManager = GameObject.FindObjectOfType <StairManager>(); startPrompt.SetActive(true); isPlaying = false; }
// Use this for initialization void Start() { // init input manager initInputEventHandler(); animator = GetComponent <Animator> (); whipAttManager = GetComponent <WhipAttackManager> (); stairManager = GetComponent <StairManager> (); collManager = GetComponent <CollisionManager> (); subWeaponManager = GetComponent <SubWeaponManager> (); hurtManager = GetComponent <HurtManager> (); collManager.ExitGround += handleOnExitGround; Flip(); // since the raw sprite face left }
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); } }
void OnTriggerEnter2D(Collider2D other) { Debug.Log("STAIR: Enter Trigger of Going up stairs"); GameObject player = other.gameObject; StairManager stairMan = player.GetComponent <StairManager>(); if (!stairMan) { Debug.Log("The colliding game object doesn't have stair manager"); return; } stairMan.switchToState(StairManager.ON_STAIR_AREA.PrepDown, stairFacing, gameObject); }
void OnTriggerExit2D(Collider2D other) { Debug.Log("STAIR: Exit Trigger of Going up stairs"); GameObject player = other.gameObject; StairManager stairMan = player.GetComponent <StairManager>(); if (!stairMan) { Debug.Log("The colliding game object doesn't have stair manager"); return; } if (stairMan.onStairArea == StairManager.ON_STAIR_AREA.PrepDown) { stairMan.onStairArea = StairManager.ON_STAIR_AREA.Not; } }
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); } } } }