Exemple #1
0
    private void RaycastLook()
    {
        // 1. get mouse position in world space
        Vector3 worldMousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 100f));
        //2. get direction vector from camera position to mouse position in world space
        Vector3 direction = worldMousePosition - Camera.main.transform.position;
        //3. if raycast hit distance <= 10 and direction is camera look at
        RaycastHit hit;

        if (Physics.Raycast(Camera.main.transform.position, direction, out hit, 10f))
        {
            // 5. Destroy game object
            if (hit.collider.gameObject.tag == "WindowPiece")
            {
                Debug.DrawLine(Camera.main.transform.position, hit.point, Color.green, 0.5f);
                if (Input.GetMouseButton(0))
                {
                    colledtedItem.Add(hit.collider.gameObject.name);
                    hud.SetCollectionCount((short)colledtedItem.Count, 21);
                    Destroy(hit.collider.gameObject);
                    if (colledtedItem.Count == 21)
                    {
                        hud.RedCursor();
                        hud.ChangeCursorTips("");
                        hud.ShowWindowTrigger();
                    }
                }
                else
                {
                    hud.GreenCursor();
                    hud.ChangeCursorTips("Podnieś");
                }
            }
            else
            {
                hud.ChangeCursorTips("");
                hud.RedCursor();
                Debug.DrawLine(Camera.main.transform.position, direction, Color.red, 0.5f);
            }
        }
        //4. if raycast hit distance < 10 and direction is camera look at
        else
        {
            hud.RedCursor();
            hud.ChangeCursorTips("");
        }
    }
 private void Update()
 {
     if (p1Correct && p2Correct && p3Correct && p4Correct && p5Correct && p6Correct && p7Correct)
     {
         gameManager.Invoke("PuzzleHidden", 2.0f);
         hud.Invoke("PuzzleHidden", 2.0f);
         Invoke("ResetStartPositionPuzzle", 2.0f);
         ResetPuzzle();
         hud.ChangeCursorTips("Witraż ułożony");
         hud.checkWindowTrigger("Udało się odnowić zniszczenia");
     }
 }
Exemple #3
0
 private void OnTriggerEnter(Collider other)
 {
     if (other.gameObject.tag == "LvlTrigger")
     {
         hud.ChangeCursorTips("Press E");
     }
     else if (other.gameObject.tag == "WindowPuzzle")
     {
         hud.ChangeCursorTips("Press E");
     }
 }