/// <summary> /// Unity Function. Collision checker if the breakable object was hit by the hammer. /// </summary> /// <param name="collision">Collision</param> void OnCollisionEnter2D(Collision2D collision) { if (!isBroken) { if (collision.collider.gameObject.layer == LayerMask.NameToLayer("HammerBreaker")) // Hammer { HammerObject hammer = collision.collider.gameObject.GetComponentInParent <HammerObject> (); if (hammer.IsAttacking()) { this.Break(); } } else if (collision.collider.gameObject.GetComponent <NeedleController>() != null) // Needle { Debug.Log("NEEDLE HAS HIT"); NeedleThrowing needleThrowing = collision.collider.gameObject.GetComponent <NeedleThrowing> (); NeedleController needle = collision.collider.gameObject.GetComponent <NeedleController> (); needleThrowing.setPullTowards(false); needleThrowing.setHookPullTowards(false); needle.hasHit = true; // NeedleController needle = collision.collider.gameObject.GetComponent<NeedleController>(); // Break (); } } }
// Use this for initialization void Awake() { playerTransform = GameObject.FindObjectOfType <PlayerYuni> ().gameObject.transform; // GameObject.FindGameObjectWithTag ("Player").transform; playerAnimator = playerTransform.gameObject.GetComponent <Animator> (); playerSpriteRenderer = playerTransform.gameObject.GetComponent <SpriteRenderer> (); this.playerAttack = playerTransform.gameObject.GetComponent <PlayerAttack> (); spriteRenderer = GetComponent <SpriteRenderer> (); needleCollider = GetComponent <Collider2D> (); threadRenderer = GetComponent <LineRenderer> (); needleController = GetComponent <NeedleController> (); needleExtendedTransform = needleController.gameObject.GetComponentInChildren <Transform> ().position; // NEW @Candy this.playerYuni = GameObject.FindObjectOfType <PlayerYuni>(); this.playerMovement = playerYuni.GetPlayerMovement(); needleCollider.enabled = false; flying = false; pullTowards = false; GameController_v7.Instance.GetPauseController().onContinueGame += NeedleUpdate; GameController_v7.Instance.GetPauseController().onPauseGame += Pause; GameController_v7.Instance.GetPauseController().onContinueGame += Continue; }
public void HitEvents(NeedleController needle) { // Continued by BrokenClone Deactivat() GameController_v7.Instance.GetPauseController().Pause(); needle.hasHit = needle.onlyHitOnce; #if UNITY_ANDROID // EventManager.DisableJumpButton (); // EventManager.ToggleSwitchButton (false); // GameController_v7.Instance.GetEventManager().ToggleLeftRightButtons(false); Parameters parameters = new Parameters(); parameters.PutExtra("FLAG", false); EventBroadcaster.Instance.PostEvent(EventNames.TOGGLE_JUMP, parameters); parameters = new Parameters(); parameters.PutExtra("FLAG", true); EventBroadcaster.Instance.PostEvent(EventNames.TOGGLE_INTERACT, parameters); parameters = new Parameters(); parameters.PutExtra("FLAG", false); EventBroadcaster.Instance.PostEvent(EventNames.TOGGLE_SWITCH_WEAPON_BUTTON, parameters); EventBroadcaster.Instance.PostEvent(EventNames.TOGGLE_LEFT_RIGHT_BUTTONS, parameters); #endif // TODO Record Data? }
private void Update() { timer = Mathf.Max(timer - Time.deltaTime, 0f); if (timer > 0) { return; } if (Input.GetAxis("Vertical") == 0 && Input.GetAxis("Horizontal") == 0) { return; } if (movement.Active && Input.GetButtonDown("Vertical") && Input.GetAxis("Vertical") < 0) { movement.Active = false; } else if (!movement.Active && Input.GetKeyDown(KeyCode.X)) { //movement.Active = true; StartCoroutine(GainControl()); GameObject go = Instantiate(needlePrefab, transform); NeedleController nc = go.GetComponent <NeedleController>(); nc.Direction = Vector3.up * Input.GetAxis("Vertical") + Vector3.right * Input.GetAxis("Horizontal"); nc.IgnorePlatform = movement.OnPlatform; nc.Player = movement; timer = 1f; } }
void OnTriggerEnter2D(Collider2D other) { if (other.gameObject.GetComponent <NeedleThrowing>()) { Debug.Log("HOOK NEEDLE HIT"); NeedleController needleController = other.gameObject.GetComponent <NeedleController> (); NeedleThrowing needleThrowing = other.gameObject.GetComponent <NeedleThrowing> (); if (needleThrowing.getPlayerAttack().HasThread()) { needleThrowing.setExtendedNeedleTransform(gameObject.transform.position); needleThrowing.setPullTowards(true); needleThrowing.setHookPullTowards(true); // needleThrowing.setExtendedNeedleTransform (GameObject.FindGameObjectWithTag("NeedleExtendedTransform").transform.position); // Physics2D.IgnoreCollision (needleThrowing.getPlayerMovement().gameObject.GetComponent<Collider2D>(), gameObject.GetComponent <Collider2D> ()); needleController.hasHit = true; } } // else if (other.gameObject.CompareTag ("Player")) { // PlayerMovement player = other.GetComponent<PlayerMovement> (); // // player.transform.position = Vector3.MoveTowards (player.transform.position, transform.position, 1 * Time.deltaTime); // } }
/// <summary> /// Unity Function. Check if another game object's collider entered the sky block's collider. /// /// If it is the needle, break the sky block. /// </summary> /// <param name="other"></param> void OnTriggerEnter2D(Collider2D other) { if (other.GetComponent <NeedleController> () != null) { NeedleController needle = other.GetComponent <NeedleController> (); NeedleThrowing needleThrowing = other.gameObject.GetComponent <NeedleThrowing> (); this.Split(needle.GetSliceCount(), needle, needleThrowing); this.HasBeenHit(); } }
void OnTriggerEnter2D(Collider2D other) { // Only needle can interact on trigger if (other.GetComponent <NeedleController> () != null) { NeedleController needle = other.GetComponent <NeedleController> (); this.HitEvents(needle); this.Interact(needle.GetSliceCount()); } }
// When this is solved, allow needle pull/jump void OnCollisionEnter2D(Collision2D collision) { GameObject other = collision.collider.gameObject; if (this.isTangible && other.GetComponent <NeedleController> () != null && !other.GetComponent <NeedleController> ().hasHit) { NeedleController needle = other.GetComponent <NeedleController> (); this.Manipulate(needle); } }
/// <summary> /// Starts this instance. /// </summary> void Start() { needle = Instantiate(needlePrefab, transform.position, Quaternion.identity); needleThrowing = needle.GetComponent <NeedleThrowing> (); needleController = needle.GetComponent <NeedleController> (); // if (PlayerPrefs.HasKey ("Player_" + GameController_v7.Instance.GetObjectStateManager().currentPlayerName)) { // string playerJSON = PlayerPrefs.GetString ("Player_" + GameController_v7.Instance.GetObjectStateManager().currentPlayerName); // PlayerJSONParams playerStats = JsonUtility.FromJson<PlayerJSONParams> (playerJSON); // this.hasNeedle = playerStats.hasNeedle; // this.hasHammer = playerStats.hasHammer; // this.hasThread = playerStats.hasThread; // this.equippedDenominator = playerStats.equppedDenominator; // } this.player = GameObject.FindObjectOfType <PlayerYuni>().GetComponent <PlayerYuni>(); playerAnimator = player.GetPlayerAnimator(); playerController = player.GetPlayerMovement(); this.fractionNumeratorLabelObject = this.fractionNumeratorLabel.gameObject; this.fractionLabelObject.SetActive(false); this.numeratorLabelObject.SetActive(false); this.listTextMesh = new List <TextMesh> (); listTextMesh.Add(numeratorLabel); listTextMesh.Add(fractionNumeratorLabel); listTextMesh.Add(fractionDenominatorLabel); EventBroadcaster.Instance.AddObserver(EventNames.ON_LCD_UNPAUSE, this.IsLCDHit); this.hammerAttack.SyncWithEquippedDenominator(this.equippedDenominator); Debug.Log("<color=green>Equipped is " + equippedDenominator + "</color>"); this.needleController.SyncWireSliceCountWithEquippedDenominator(this.equippedDenominator); this.hammerAttack.DisableBreaker(); if (!this.HasHammer()) { #if UNITY_ANDROID GameController_v7.Instance.GetMobileUIManager().ToggleMobileControls(false); GameController_v7.Instance.GetMobileUIManager().ToggleBaseWithPickupControls(true); #endif } if (this.HasNeedle()) { EventBroadcaster.Instance.PostEvent(EventNames.YUNI_ACQUIRED_NEEDLE); } // EventBroadcaster.Instance.AddObserver (EventNames.ON_LCD_DONE, this.IsLCDDonePlaying); }
/// <summary> /// Slices the sky block into fragments. The fragments are then dropped to be picked up by the player avatar. /// </summary> /// <param name="pieceCount">Number of pieces</param> /// <param name="needle">Needle that sliced the sky block.</param> /// <param name="needleThrowing">Needle Throwing behaviour</param> public void Split(float pieceCount, NeedleController needle, NeedleThrowing needleThrowing) { // You can only split if the numerator is greater than 0 // TODO: Add a constraint for splitting a piece too small (since players can cascadingly split) // i.e. Split to 4, return 2/4, Split to 8, and so on. Maybe check if the decimal value is past a certain threshold // and if its too small, prompt the user that he/she can't do that via Yuni/Hints // Debug.Log ("num is "+this.GetNumerator()); // Debug.Log ("den is "+this.GetDenominator()); // Debug.Log ("divided by "+pieceCount); if (this.GetNumerator() > 0) { if (pieceCount <= 0 && needle != null) { // Deflect needle if pieceCount is 0 Debug.Log("NEEDLE HAS HIT"); needleThrowing.setPullTowards(false); needleThrowing.setHookPullTowards(false); needle.hasHit = true; } else if (this.NotTooSmall(pieceCount)) { Debug.Log("Entered Split"); float newDenominator = this.GetDenominator() * pieceCount; // float newNumerator = this.GetNumerator () * pieceCount; // Create a SkyFragmentPiece for each pieceCount float speed = 500f; int originalCount = skyFragmentPieces.Count; for (int i = 0; i < pieceCount; i++) { this.skyFragmentPieces.Add(CreateSkyFragmentPiece(this.skyBlockParent.GetDetachedManager().gameObject, (int)this.GetNumerator(), (int)newDenominator)); this.skyFragmentPieces [originalCount + i].transform.localPosition = new Vector3(this.skyFragmentPieces [i].GetWidth() * i, 0f, 0f); this.skyFragmentPieces [originalCount + i].GetRigidBody2D().AddRelativeForce(Random.onUnitSphere * speed); this.skyFragmentPieces [originalCount + i].SetPiecesNeverBreak(this.piecesNeverBreak); } this.SetNumerator(0); this.SetDenominator(newDenominator); this.HasBeenBroken(); } else { // Too small. Yuni prompt. // TODO: Yuni Hints } } }
private IEnumerator MoveVertical(KeyCode pressedKey) { Vector3 originalPosition = this.transform.position; Vector3 cachedPosition = this.transform.position; Vector3 finalPosition = cachedPosition; bool synapseHit = false; while (Input.GetKey(pressedKey)) { if (pressedKey == this.upKey) { finalPosition = new Vector3(originalPosition.x, originalPosition.y + this.maxUpDistance, originalPosition.z); if (synapseHit == false) { NeedleController.onSynapseHit(this.upSynapse); synapseHit = true; } } else if (pressedKey == this.downKey) { finalPosition = new Vector3(originalPosition.x, originalPosition.y - this.maxDownDistance, originalPosition.z); if (synapseHit == false) { NeedleController.onSynapseHit(this.downSynapse); synapseHit = true; } } cachedPosition = Vector3.Lerp(cachedPosition, finalPosition, this.moveSpeed); this.transform.position = cachedPosition; yield return(null); } while (cachedPosition != originalPosition) { if (Vector3.Magnitude(cachedPosition - originalPosition) < 0.01f) { cachedPosition = originalPosition; } else { cachedPosition = Vector3.Lerp(cachedPosition, originalPosition, this.moveSpeed); } this.transform.position = cachedPosition; } this.moveCoroutine = null; }
void OnTriggerEnter2D(Collider2D other) { // NOTE: !isFilling is to prevent the player from targeting the object WHILE the filling animation is playing if (!isTangible && !isFilling && other.gameObject.CompareTag("Needle") && !other.gameObject.GetComponent <NeedleController>().hasHit) { Debug.Log("Enter Trigger"); // this.disabledTransparency (); NeedleController needle = other.gameObject.GetComponent <NeedleController> (); needle.hasHit = needle.onlyHitOnce; #if UNITY_ANDROID // EventManager.DisableJumpButton (); // EventManager.ToggleSwitchButton (false); //// EventManager.Instance.ToggleLeftRightButtons(false); // GameController_v7.Instance.GetEventManager().ToggleLeftRightButtons(false); Parameters parameters = new Parameters(); parameters.PutExtra("FLAG", false); EventBroadcaster.Instance.PostEvent(EventNames.TOGGLE_JUMP, parameters); parameters = new Parameters(); parameters.PutExtra("FLAG", true); EventBroadcaster.Instance.PostEvent(EventNames.TOGGLE_INTERACT, parameters); parameters = new Parameters(); parameters.PutExtra("FLAG", false); EventBroadcaster.Instance.PostEvent(EventNames.TOGGLE_SWITCH_WEAPON_BUTTON, parameters); EventBroadcaster.Instance.PostEvent(EventNames.TOGGLE_LEFT_RIGHT_BUTTONS, parameters); #endif this.clone(needle.GetSliceCount()); RecordData(); } if (other.gameObject.CompareTag("Player")) { Debug.Log("PLAYER COLLIDING"); // animator.SetBool("isCollidingPlayer", true); } if (other.gameObject.CompareTag("Hammer")) { Debug.Log("Hammer is colliding"); } }
void Manipulate(NeedleController needle) { needle.hasHit = true; this.rigidBody2d.velocity = Vector2.zero; this.rigidBody2d.AddRelativeForce(Vector2.up * 500f); }
private IEnumerator MoveHorizontal(KeyCode pressedKey) { Transform originalTransform = this.transform; Transform cachedTransform = this.transform; float finalRotation = (pressedKey == this.leftKey) ? this.maxRotation : 360 - this.maxRotation; float thisRotationSpeed = (pressedKey == this.leftKey) ? this.rotationSpeed : -this.rotationSpeed; if (this.side == NeedleSide.Left && pressedKey == this.rightKey) { finalRotation += ((360f - finalRotation) / 2.5f); } else if (this.side == NeedleSide.Right && pressedKey == this.leftKey) { finalRotation = finalRotation - (finalRotation / 2.5f); } bool synapseHit = false; while (Input.GetKey(pressedKey)) { if (cachedTransform.eulerAngles.z != finalRotation) { cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, cachedTransform.eulerAngles.z + thisRotationSpeed); if (pressedKey == this.leftKey && Mathf.Abs(cachedTransform.eulerAngles.z) > finalRotation) { cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, finalRotation); if (synapseHit == false) { NeedleController.onSynapseHit(this.leftSynapse); synapseHit = true; } } else if (pressedKey == this.rightKey && Mathf.Abs(cachedTransform.eulerAngles.z) < finalRotation) { cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, finalRotation); if (synapseHit == false) { NeedleController.onSynapseHit(this.rightSynapse); synapseHit = true; } } this.transform.rotation = cachedTransform.rotation; } yield return(null); } while (cachedTransform.eulerAngles.z != 0) { cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, cachedTransform.eulerAngles.z - thisRotationSpeed); if (pressedKey == this.leftKey && cachedTransform.eulerAngles.z > 300) { cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, 0); } else if (pressedKey == this.rightKey && cachedTransform.eulerAngles.z < finalRotation) { cachedTransform.eulerAngles = new Vector3(cachedTransform.eulerAngles.x, cachedTransform.eulerAngles.y, 0); } this.transform.rotation = cachedTransform.rotation; yield return(null); } this.moveCoroutine = null; }