Exemple #1
0
    void Update()
    {
        if (placeGameBoard.Placed() && Input.touchCount > 0)
        {
            Vector2 touchPosition = Input.GetTouch(0).position;
            // Convert the 2d screen point into a ray.
            Ray ray = arCamera.ScreenPointToRay(touchPosition);
            // Check if this hits an object within 100m of the user.
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 100))
            {
                // Check that the object is interactable.
                if (hit.transform.tag == "Interactable")
                {
                    // Call the OnTouch function.
                    // Note the use of OnTouch3D here lets us
                    // call any class inheriting from OnTouch3D.
                    hit.transform.GetComponent <OnTouch3D>().OnTouch(tictactoe.GetPlayer());

                    // make the object unclickable
                    hit.transform.tag = "Finish";
                    tictactoe.UpdateBoard(hit.transform.name);
                }
            }
        }
    }
Exemple #2
0
    void Update()
    {
        if (!gb.GetComponent <GameManager>().gameOver)
        {
            if (placeGameBoard.Placed() && Input.touchCount > 0)
            {
                Vector2 touchPosition = Input.GetTouch(0).position;
                // Convert the 2d screen point into a ray.
                Ray ray = arCamera.ScreenPointToRay(touchPosition);
                // Check if this hits an object within 100m of the user.
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 100))
                {
                    Debug.Log("something was pressed");

                    // Check that the object is interactable.
                    if (hit.transform.tag == "interactable")
                    {
                        // Call the OnTouch function.
                        // Note the use of OnTouch3D here lets us
                        // call any class inheriting from OnTouch3D.
                        Debug.Log("it was interactable");
                    }
                    hit.transform.GetComponent <OnTouch3D>().OnTouch();
                }
            }
        }
    }
 void Update()
 {
     if (placeGameBoard.Placed() && Input.touchCount > 0)
     {
         Vector2 touchPosition = Input.GetTouch(0).position;
         // Convert the 2d screen point into a ray.
         Ray ray = arCamera.ScreenPointToRay(touchPosition);
         // Check if this hits an object within 100m of the user.
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, 100))
         {
             // Check that the object is interactable.
             if (hit.transform.tag == "Interactable")
             {
                 if (victory == false)
                 {
                     int button_num     = hit.transform.GetComponent <OnTouch3D>().getButtonNum();
                     int current_status = buttonStatuses[button_num];
                     if (current_status == -1)
                     {
                         hit.transform.GetComponent <OnTouch3D>().setColor(currentPlayer);
                         buttonStatuses[button_num] = currentPlayer;
                         checkVictory(button_num);
                         currentPlayer = 1 - currentPlayer;
                     }
                 }
             }
         }
     }
 }
Exemple #4
0
    void Update()
    {
        if (remainingTime <= 0 && placeGameBoard.Placed() && Input.touchCount > 0 && !gameStateManager.GameOver())
        {
            Vector2 touchPosition = Input.GetTouch(0).position;
            // Convert the 2d screen point into a ray.
            Ray ray = arCamera.ScreenPointToRay(touchPosition);
            // Check if this hits an object within 100m of the user.
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit, 100))
            {
                // Check that the object is interactable.
                if (hit.transform.tag == "Interactable")
                {
                    // Call the OnTouch function.
                    // Note the use of OnTouch3D here lets us
                    // call any class inheriting from OnTouch3D.

                    hit.transform.GetComponent <OnTouch3D>().OnTouch(gameStateManager);
                }
                remainingTime = debounceTime;
            }
        }
        else
        {
            remainingTime -= Time.deltaTime;
        }
    }
Exemple #5
0
    void Update()
    {
        var count = Input.touchCount;

        if (placeGameBoard.Placed() && count > 0)
        {
            for (int i = 0; i < count; i++)
            {
                Vector2 touchPosition = Input.GetTouch(i).position;
                // Convert the 2d screen point into a ray.
                Ray ray = arCamera.ScreenPointToRay(touchPosition);
                // Check if this hits an object within 100m of the user.
                RaycastHit hit;
                if (Physics.Raycast(ray, out hit, 100))
                {
                    // Check that the object is interactable.
                    if (interactList.Any(tag => hit.transform.tag == tag))
                    {
                        // Call the OnTouch function.
                        // Note the use of OnTouch3D here lets us
                        // call any class inheriting from OnTouch3D.
                        hit.transform.GetComponent <OnTouch3D>().OnTouch();
                    }
                }
            }
        }
    }
 void Update()
 {
     if (!placeGameBoard.Placed())
     {
         gameState = State.PAUSED;
     }
     else
     {
         gameState = State.ONGOING;
         if (Checkresult())
         {
             gameState = State.END;
         }
         if (gameState == State.END)
         {
             resultText.gameObject.SetActive(true);
             if (result == PlayerAndResult.P1 && mode == Mode.PVC)
             {
                 resultText.text  = "Win!";
                 resultText.color = Color.red;
             }
             else if (result == PlayerAndResult.P1 && mode == Mode.PVP)
             {
                 resultText.text  = "P1 Win!";
                 resultText.color = Color.red;
             }
             if (result == PlayerAndResult.P2)
             {
                 resultText.text  = "P2 Win!";
                 resultText.color = Color.blue;
             }
             else if (result == PlayerAndResult.AI)
             {
                 resultText.text  = "Lose!";
                 resultText.color = Color.blue;
             }
             else if (result == PlayerAndResult.TIE)
             {
                 resultText.text  = "Tie!";
                 resultText.color = Color.yellow;
             }
         }
         if (gameState == State.ONGOING)
         {
             resultText.gameObject.SetActive(false);
             if (player == PlayerAndResult.AI)
             {
                 AIDecision();
             }
         }
     }
 }
 // Update is called once per frame
 void Update()
 {
     if (placeGameBoard.Placed() && Input.touchCount > 0)
     {
         Vector2    touchPosition = Input.GetTouch(0).position;
         Ray        ray           = arCamera.ScreenPointToRay(touchPosition);
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, 100))
         {
             if (hit.transform.tag == "Interactable")
             {
                 hit.transform.GetComponent <OnTouch3D>().OnTouch();
             }
         }
     }
 }
Exemple #8
0
    // Update is called once per frame
    void Update()
    {
        if (placeGameBoard.Placed() && Input.touchCount > 0)
        {
            Vector2 touchPosition = Input.GetTouch(0).position;
            //convert 2d position into a ray
            Ray ray = arCamera.ScreenPointToRay(touchPosition);
            //check if this hits an object < 100m fo the user
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, 100))
            {
                //interactable object + game is not finished
                if (hit.transform.tag == "Interactable" && !GeneralControl.finished)
                {
                    hit.transform.GetComponent <OnTouch3D>().OnTouch();
                }
            }
        }
    }
 void Update()
 {
     if (placeGameBoard.Placed() && gameplayManager.GameStarted() && Input.touchCount > 0)
     {
         Vector2 touchPosition = Input.GetTouch(0).position;
         // Convert the 2d screen point into a ray.
         Ray ray = arCamera.ScreenPointToRay(touchPosition);
         // Check if this hits an object within 100m of the user.
         RaycastHit hit;
         if (Physics.Raycast(ray, out hit, 100))
         {
             // Check that the object is interactable.
             if (hit.transform.CompareTag("Cross"))
             {
                 // Call the OnTouch function.
                 // Note the use of OnTouch3D here lets us
                 // call any class inheriting from OnTouch3D.
                 hit.transform.GetComponent <OnTouch3D>().OnTouch();
             }
         }
     }
 }
Exemple #10
0
    // Update is called once per frame
    void Update()
    {
        CheckWin();
        if (!once && Input.touchCount > 0)
        {
            once = true;
        }
        else
        {
            if (placeGameBoard.Placed() && Input.touchCount > 0)
            {
                Vector2 touchPosition = Input.GetTouch(0).position;
                // Convert the 2d screen point into a ray.
                Ray ray = arCamera.ScreenPointToRay(touchPosition);
                // Check if this hits an object within 100m of the user.
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit, 100))
                {
                    // Check that the object is interactable.
                    if (hit.transform.tag == "Interactable")
                    {
                        turn += 1;
                        switch (hit.transform.name)
                        {
                        case "Tile0":
                            if (turn % 2 == 0)
                            {
                                Debug.Log("tile 0 android");
                                tile0android = true;
                                InstantiatePrefab(androidPrefab, GameObject.Find("Tile0").transform);
                                GameObject.Find("Tile0").GetComponent <MeshRenderer>().material = androidMat;
                            }
                            else
                            {
                                Debug.Log("tile 0 apple");
                                tile0apple = true;
                                GameObject.Find("Tile0").GetComponent <MeshRenderer>().material = appleMat;
                                InstantiatePrefab(applePrefab, GameObject.Find("Tile0").transform);
                            }
                            break;

                        case "Tile1":
                            if (turn % 2 == 0)
                            {
                                Debug.Log("tile 1 android");
                                tile1android = true;
                                GameObject.Find("Tile1").GetComponent <MeshRenderer>().material = androidMat;
                                InstantiatePrefab(androidPrefab, GameObject.Find("Tile1").transform);
                            }
                            else
                            {
                                Debug.Log("tile 1 apple");
                                tile1apple = true;
                                GameObject.Find("Tile1").GetComponent <MeshRenderer>().material = appleMat;
                                InstantiatePrefab(applePrefab, GameObject.Find("Tile1").transform);
                            }
                            break;

                        case "Tile2":
                            if (turn % 2 == 0)
                            {
                                Debug.Log("tile 2 android");
                                tile2android = true;
                                GameObject.Find("Tile2").GetComponent <MeshRenderer>().material = androidMat;
                                InstantiatePrefab(androidPrefab, GameObject.Find("Tile2").transform);
                            }
                            else
                            {
                                Debug.Log("tile 2 apple");
                                tile2apple = true;
                                GameObject.Find("Tile2").GetComponent <MeshRenderer>().material = appleMat;
                                InstantiatePrefab(applePrefab, GameObject.Find("Tile2").transform);
                            }
                            break;

                        case "Tile3":
                            if (turn % 2 == 0)
                            {
                                tile3android = true;
                                GameObject.Find("Tile3").GetComponent <MeshRenderer>().material = androidMat;
                                InstantiatePrefab(androidPrefab, GameObject.Find("Tile3").transform);
                            }
                            else
                            {
                                tile3apple = true;
                                GameObject.Find("Tile3").GetComponent <MeshRenderer>().material = appleMat;
                                InstantiatePrefab(applePrefab, GameObject.Find("Tile3").transform);
                            }
                            break;

                        case "Tile4":
                            if (turn == 0)
                            {
                                break;
                            }
                            if (turn % 2 == 0)
                            {
                                tile4android = true;
                                GameObject.Find("Tile4").GetComponent <MeshRenderer>().material = androidMat;
                                InstantiatePrefab(androidPrefab, GameObject.Find("Tile4").transform);
                            }
                            else
                            {
                                tile4apple = true;
                                GameObject.Find("Tile4").GetComponent <MeshRenderer>().material = appleMat;
                                InstantiatePrefab(applePrefab, GameObject.Find("Tile4").transform);
                            }
                            break;

                        case "Tile5":
                            if (turn % 2 == 0)
                            {
                                tile5android = true;
                                GameObject.Find("Tile5").GetComponent <MeshRenderer>().material = androidMat;
                                InstantiatePrefab(androidPrefab, GameObject.Find("Tile5").transform);
                            }
                            else
                            {
                                tile5apple = true;
                                GameObject.Find("Tile5").GetComponent <MeshRenderer>().material = appleMat;
                                InstantiatePrefab(applePrefab, GameObject.Find("Tile5").transform);
                            }
                            break;

                        case "Tile6":
                            if (turn % 2 == 0)
                            {
                                tile6android = true;
                                GameObject.Find("Tile6").GetComponent <MeshRenderer>().material = androidMat;
                                InstantiatePrefab(androidPrefab, GameObject.Find("Tile6").transform);
                            }
                            else
                            {
                                tile6apple = true;
                                GameObject.Find("Tile6").GetComponent <MeshRenderer>().material = appleMat;
                                InstantiatePrefab(applePrefab, GameObject.Find("Tile6").transform);
                            }
                            break;

                        case "Tile7":
                            if (turn % 2 == 0)
                            {
                                tile7android = true;
                                GameObject.Find("Tile7").GetComponent <MeshRenderer>().material = androidMat;
                                InstantiatePrefab(androidPrefab, GameObject.Find("Tile7").transform);
                            }
                            else
                            {
                                tile7apple = true;
                                GameObject.Find("Tile7").GetComponent <MeshRenderer>().material = appleMat;
                                InstantiatePrefab(applePrefab, GameObject.Find("Tile7").transform);
                            }
                            break;

                        case "Tile8":
                            if (turn % 2 == 0)
                            {
                                tile8android = true;
                                GameObject.Find("Tile8").GetComponent <MeshRenderer>().material = androidMat;
                                InstantiatePrefab(androidPrefab, GameObject.Find("Tile8").transform);
                            }
                            else
                            {
                                tile8apple = true;
                                GameObject.Find("Tile8").GetComponent <MeshRenderer>().material = appleMat;
                                InstantiatePrefab(applePrefab, GameObject.Find("Tile8").transform);
                            }
                            break;

                        default:
                            break;
                        }
                    }
                }
            }
        }
    }