// Use this for initialization void Start() { Debug.Log("executing touchevents script"); bunnyIsTapped = false; haptic1 = GameObject.Find("SquareHaptic1").GetComponent <HapticSquare>(); haptic1.DeactivateHaptic(); haptic3 = GameObject.Find("SquareHaptic3").GetComponent <HapticSquare>(); haptic3.DeactivateHaptic(); haptic5 = GameObject.Find("SquareHaptic5").GetComponent <HapticSquare>(); haptic5.DeactivateHaptic(); }
// Update is called once per frame void Update() { // TAP BUNNY // OR // TAP BUTTON // if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { //transform the touch position into world space from screen space and store it. touchPosWorld = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); Vector2 touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y); //raycast with this information. If we have hit something we can process it. RaycastHit2D hitInformation = Physics2D.Raycast(touchPosWorld2D, Camera.main.transform.forward); if (hitInformation.collider != null) { //We should have hit something with a 2D Physics collider! //touchedBunny should be the object someone touched. //if (hitInformation.transform.gameObject.tag == "Bunny") // Capsule collider is the top collider which is for touch events //if (hitInformation.collider.tag == "Bunny" && hitInformation.collider is CapsuleCollider2D) if (hitInformation.collider.tag.StartsWith("Bunny")) { Debug.Log(hitInformation.collider.name); touchedBunny = hitInformation.transform.gameObject; Debug.Log(touchedBunny.name); bunnyIsTapped = true; offset = touchPosWorld - touchedBunny.transform.position; //Debug.Log("Touched " + touchedBunny.name); //Activate the haptics view switch (touchedBunny.tag) { case "Bunny1": haptic1.ActivateHaptic(); break; case "Bunny3": haptic3.ActivateHaptic(); break; case "Bunny5": haptic5.ActivateHaptic(); break; } } else if (hitInformation.collider.tag == "Button") { touchedBunny = hitInformation.transform.gameObject; touchedBunny.GetComponent <Button>().Next(); } } } // MOVE BUNNY // if (Input.touchCount > 0 && bunnyIsTapped && Input.GetTouch(0).phase == TouchPhase.Moved) { // Get movement of the finger since last frame touchPosWorld = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); Vector3 newBunnyPosition = touchPosWorld - offset; touchedBunny.transform.position = new Vector3(newBunnyPosition.x, newBunnyPosition.y, newBunnyPosition.z); //Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition; //float speed = 0.1f; // Move object across XY plane //touchedBunny.transform.Translate(touchDeltaPosition.x * speed, touchDeltaPosition.y * speed, 0); } // END MOVE BUNNY & DETECT IF SAT ON A SEAT// if (Input.touchCount > 0 && bunnyIsTapped && Input.GetTouch(0).phase == TouchPhase.Ended) { //Deactivate the haptics view switch (touchedBunny.tag) { case "Bunny1": haptic1.DeactivateHaptic(); break; case "Bunny3": haptic3.DeactivateHaptic(); break; case "Bunny5": haptic5.DeactivateHaptic(); break; } bunnyIsTapped = false; //end the touch //if (GlobalVariables.collidedSeat != null) touchedBunny.GetComponent <BunnyPlayer>().TouchUp(); } }
private void StartTasks() { thisPlayerLog = GameObject.Find("EventSystem").GetComponent <PlayerLog>(); hint = GameObject.Find("Hint"); hint.SetActive(false); confirmPage = GameObject.Find("Confirm Finish"); confirmPage.SetActive(false); Debug.Log("this circuit: " + GlobalVariables.thisTask); haptic = GameObject.Find("HapticSquare").GetComponent <HapticSquare>(); nextButton = GameObject.Find("Next Button"); finishButton = GameObject.Find("Finish Button"); buttonC1 = GameObject.Find("Circuit1 Button"); buttonC2 = GameObject.Find("Circuit2 Button"); buttonC3 = GameObject.Find("Circuit3 Button"); sliderR = GameObject.Find("SliderR"); finishButton.SetActive(false); buttonC1.SetActive(false); buttonC2.SetActive(false); buttonC3.SetActive(false); sliderR.SetActive(false); //set button sprites buttonC1Sprite = Resources.Load <Sprite>("Sprites/Buttons/circuit1"); buttonC1ClickedSprite = Resources.Load <Sprite>("Sprites/Buttons/circuit1clicked"); buttonC2Sprite = Resources.Load <Sprite>("Sprites/Buttons/circuit2"); buttonC2ClickedSprite = Resources.Load <Sprite>("Sprites/Buttons/circuit2clicked"); buttonC3Sprite = Resources.Load <Sprite>("Sprites/Buttons/circuit3"); buttonC3ClickedSprite = Resources.Load <Sprite>("Sprites/Buttons/circuit3clicked"); buttonReadSprite = Resources.Load <Sprite>("Sprites/Buttons/read"); buttonReadClickedSprite = Resources.Load <Sprite>("Sprites/Buttons/readclicked"); GlobalVariables.hintOn = false; switch (GlobalVariables.thisTask) { case 1: circuitSprite1 = Resources.Load <Sprite>("Sprites/Circuits/bg-circuit1"); taskSprite = Resources.Load <Sprite>("Sprites/Buttons/task1"); currentHapticType = HapticSquare.HapticType.STRIPEHIGHH; //quick solution for fixing a bug haptic.UpdateHaptics(currentHapticType); currentHapticType = HapticSquare.HapticType.STRIPEHIGHV; haptic.UpdateHaptics(currentHapticType); thisPlayerLog.AddEvent("=============================================\n" + "t = " + Time.time.ToString() + ", Start Task 1" + "\n============================================="); break; case 2: circuitSprite1 = Resources.Load <Sprite>("Sprites/Circuits/bg-circuit2"); taskSprite = Resources.Load <Sprite>("Sprites/Buttons/task2"); currentHapticType = HapticSquare.HapticType.STRIPEMEDH; //quick solution for fixing a bug haptic.UpdateHaptics(currentHapticType); currentHapticType = HapticSquare.HapticType.STRIPEMEDV; haptic.UpdateHaptics(currentHapticType); thisPlayerLog.AddEvent("=============================================\n" + "t = " + Time.time.ToString() + ", Start Task 2" + "\n============================================="); break; case 3: circuitSprite1 = Resources.Load <Sprite>("Sprites/Circuits/bg-circuit1"); taskSprite = Resources.Load <Sprite>("Sprites/Buttons/task3"); currentHapticType = HapticSquare.HapticType.STRIPEHIGHV; haptic.UpdateHaptics(currentHapticType); //activate C1 and C2 buttons buttonC1.SetActive(true); buttonC2.SetActive(true); thisPlayerLog.AddEvent("=============================================\n" + "t = " + Time.time.ToString() + ", Start Task 3" + "\n============================================="); break; case 4: circuitSprite1 = Resources.Load <Sprite>("Sprites/Circuits/bg-circuit1"); taskSprite = Resources.Load <Sprite>("Sprites/Buttons/task4"); currentHapticType = HapticSquare.HapticType.STRIPELOWH; //quick solution for fixing a bug haptic.UpdateHaptics(currentHapticType); currentHapticType = HapticSquare.HapticType.STRIPEHIGHV; haptic.UpdateHaptics(currentHapticType); //activate C1 and C2 buttons buttonC1.SetActive(true); buttonC2.SetActive(true); buttonC3.SetActive(true); thisPlayerLog.AddEvent("=============================================\n" + "t = " + Time.time.ToString() + ", Start Task 4" + "\n============================================="); break; case 5: circuitSprite1 = Resources.Load <Sprite>("Sprites/Circuits/bg-circuit4R1"); taskSprite = Resources.Load <Sprite>("Sprites/Buttons/task5"); currentHapticType = HapticSquare.HapticType.STRIPEMEDV; haptic.UpdateHaptics(currentHapticType); //activate slider sliderR.SetActive(true); //deactivate the back button nextButton.SetActive(false); finishButton.SetActive(true); thisPlayerLog.AddEvent("=============================================\n" + "t = " + Time.time.ToString() + ", Start Task 5" + "\n============================================="); break; } GlobalVariables.currentHapticType = currentHapticType; haptic.DeactivateHaptic(); GameObject bg = GameObject.Find("Background"); bg.GetComponent <Image>().sprite = circuitSprite1; //spriteR = bg.GetComponent<SpriteRenderer>(); //spriteR.sprite = circuitSprite1; GameObject taskLabel = GameObject.Find("Task Label"); taskLabel.GetComponent <Image>().sprite = taskSprite; //spriteR = taskLabel.GetComponent<SpriteRenderer>(); //spriteR.sprite = taskSprite; }
// Update is called once per frame void Update() { // TOUCH BEGIN// if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { //transform the touch position into world space from screen space and store it. touchPosWorld = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); Vector2 touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y); //raycast with this information. If we have hit something we can process it. RaycastHit2D hitInformation = Physics2D.Raycast(touchPosWorld2D, Camera.main.transform.forward); if (hitInformation.collider != null) { if (hitInformation.collider.name == "Close") { GameObject.Find("circuit-outlineS1").GetComponent <Circuit>().HideHint(); } else if (hitInformation.collider.name == "Finish") { GameObject.Find("Finish Button").GetComponent <Button>().EndSession(); } else if (hitInformation.collider.name == "Go Back") { thisPlayerLog.AddEvent("t = " + Time.time.ToString() + ", Go back to exhibit"); GameObject.Find("Confirm Finish").SetActive(false); } else if (hitInformation.collider.name.StartsWith("Zone")) { if (!GlobalVariables.hintOn) { thisPlayerLog.AddTouchEvent("Touch Down", touchPosWorld); } Debug.Log("touch down circuit"); } } touchPosWorldPrev = touchPosWorld; //GlobalVariables.interactionLog.AppendLine(Time.time.ToString() + " touch down"); } // TOUCH MOVE // if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) { //transform the touch position into world space from screen space and store it. touchPosWorld = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); Vector2 touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y); //raycast with this information. If we have hit something we can process it. RaycastHit2D hitInformation = Physics2D.Raycast(touchPosWorld2D, Camera.main.transform.forward); if (hitInformation.collider != null) { if (!touchMoveStarted) { if (!GlobalVariables.hintOn) { thisPlayerLog.AddTouchEvent("Touch Move Start ", touchPosWorld); } touchMoveStarted = true; } //We should have hit something with a 2D Physics collider, find if the circuit outline is touched string thisZone = hitInformation.transform.gameObject.tag; string thisZoneName = hitInformation.transform.gameObject.name; //determine what texture to feel, if any. FlowCurrent(thisZone, thisZoneName); } else { haptic.DeactivateHaptic(); //Debug.Log("moving out of the outline!"); if (touchMoveStarted) { if (!GlobalVariables.hintOn) { thisPlayerLog.AddTouchEvent("Touch Move End ", touchPosWorld); } touchMoveStarted = false; } } touchPosWorldPrev = touchPosWorld; } // TOUCH END // if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Ended) { //transform the touch position into world space from screen space and store it. touchPosWorld = Camera.main.ScreenToWorldPoint(Input.GetTouch(0).position); Vector2 touchPosWorld2D = new Vector2(touchPosWorld.x, touchPosWorld.y); //raycast with this information. If we have hit something we can process it. RaycastHit2D hitInformation = Physics2D.Raycast(touchPosWorld2D, Camera.main.transform.forward); if (hitInformation.collider != null && hitInformation.collider.name.StartsWith("Zone")) { if (!GlobalVariables.hintOn) { if (touchMoveStarted) { thisPlayerLog.AddTouchEvent("Touch Move End ", touchPosWorld); } thisPlayerLog.AddTouchEvent("Touch Up", touchPosWorldPrev); } touchMoveStarted = false; //Debug.Log("touch up circuit"); } haptic.DeactivateHaptic(); } }