Exemplo n.º 1
0
 void Awake()
 {
     //singlize the object door so i can call the same door from any class
     ins = this;
     //set the door angel to face the main camera
     this.transform.Rotate(new Vector3(0, 180, 0));
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        // grab input for this frame
        float horizontalInput = Input.GetAxis("Horizontal");      // A/D, LeftArrow/RightArrow
        float verticalInput   = Input.GetAxis("Vertical");        // W/S, UpArrow/DownArrow

        // transform our input values based on this transform's "right" / "forward" directions
        inputVector = transform.right * horizontalInput + transform.forward * verticalInput;

        transform.Rotate(0f, horizontalInput * Time.deltaTime * 90f, 0f);

        // normalize the inputVector so that diagonal movement isn't faster
        if (inputVector.magnitude > 1f)
        {
            inputVector = Vector3.Normalize(inputVector);
        }


        //Here's the script for checking if a door is there
        Ray   shootRay       = new Ray(transform.position, transform.forward);
        float maxRayDistance = 20f;

        Debug.DrawRay(shootRay.origin, shootRay.direction * 10, Color.yellow);

        if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("Is the player near a door? Raycast Fired!");
            RaycastHit shootRayHit = new RaycastHit();

            if (Physics.Raycast(shootRay, out shootRayHit, maxRayDistance) && shootRayHit.collider.gameObject.tag == "Door")
            {
                //The Ray hit the door!! Now we can do stuff!!!
                Debug.Log("A door was hit!");
                door = shootRayHit.transform.GetComponent <doorScript> ();

                if (door.wasVisited == false)
                {
                    door.TrickOrTreat();
                }
            }
            else
            {
                Debug.Log("No door was hit. :(");
            }
        }
    }
Exemplo n.º 3
0
    void Awake()
    {
//		gm = GameObject.FindGameObjectWithTag ("GameManager").GetComponent<gameManager>();
        door = GameObject.FindGameObjectWithTag("Door").GetComponent <doorScript>();
    }
Exemplo n.º 4
0
    private void FixedUpdate()
    {
        //if player object is not close to the target already
        //return the object clicked
        //move the player there
        //if player object is close, interact with it
        if (!flowchart.HasExecutingBlocks())
        {
            if (Input.GetMouseButtonDown(0))
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                if (Physics.Raycast(ray, out hit))
                {
                    if (hit.rigidbody != null)
                    {
                        if (hit.collider.tag == "moveEnabled")
                        {
                            moveTarget.transform.position = hit.point;
                        }
                        else if (hit.collider.tag == "clue")
                        {
                            if (Vector3.Distance(gameObject.transform.position, hit.transform.position) < 4f)
                            {
                                string name = hit.collider.name;
                                Debug.Log("you examined the " + name);
                                switch (name)
                                {
                                case "Briefcase":
                                    flowchart.ExecuteBlock("Finding-the-Suitcase");
                                    break;

                                default:
                                    Debug.LogWarning("You didn't set up this object yet!");
                                    break;
                                }
                            }
                            else
                            {
                                moveTarget.transform.position = hit.transform.position;
                            }
                        }
                        else if (hit.collider.tag == "door")
                        {
                            if (Vector3.Distance(gameObject.transform.position, hit.transform.position) < 3f)
                            {
                                doorStuff = hit.collider.gameObject.GetComponent <doorScript>();

                                if (fade != null)
                                {
                                    StartCoroutine(fade.Fade(false, doorStuff.sceneNumberToLoad));
                                }
                                else
                                {
                                    Debug.LogWarning("No fade UI in the scene!");
                                    SceneManager.LoadScene(doorStuff.sceneNumberToLoad);
                                }
                            }
                            else
                            {
                                moveTarget.transform.position = hit.transform.position;
                            }
                        }
                    }
                }
            }

            playerAgent.destination = moveTarget.position;
        }
    }
Exemplo n.º 5
0
 void Start()
 {
     playerIn  = false;
     timeCount = Time.time;
     myParent  = transform.parent.GetComponent <doorScript> ();
 }
Exemplo n.º 6
0
 private void Start()
 {
     doorScript = this.gameObject.GetComponent <doorScript>();
 }
Exemplo n.º 7
0
    // Update is called once per frame
    void Update()
    {
        guncam = GameObject.Find("Camera (1)").GetComponent <Camera>();

        float mouseX = Input.GetAxis("Mouse X") * sensitivity * Time.deltaTime;
        float mouseY = Input.GetAxis("Mouse Y") * sensitivity * Time.deltaTime;

        playerBody.Rotate(Vector3.up * mouseX);

        xRotation -= mouseY;
        xRotation  = Mathf.Clamp(xRotation, -90f, 90f);

        transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);

        Ray ray;

        ray = cam.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));

        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, 5))
        {
            if (hit.collider != null && hit.collider.gameObject.tag != "Untagged")
            {
                crossHair.localScale = new Vector3(0.1845333f, 0.1845333f, 0.1845333f);
            }
            else if (hit.collider != null && hit.collider.gameObject.tag == "Untagged")
            {
                crossHair.localScale = new Vector3(0.0989508f, 0.0989508f, 0.0989508f);
            }

            if (hit.collider.gameObject.CompareTag("door"))
            {
                door = hit.collider.gameObject.GetComponent <doorScript>();

                if (Input.GetMouseButtonDown(0) && !door.isopen)
                {
                    door.isopen = true;
                    door.audioSource.PlayOneShot(doorOpen);
                }
                else if (Input.GetMouseButtonDown(0) && door.isopen)
                {
                    door.isopen = false;
                    door.audioSource.PlayOneShot(doorClose);
                }
            }

            if (hit.collider.gameObject.CompareTag("trigger"))
            {
                if (Input.GetMouseButtonDown(0) && !isSit)
                {
                    obj = hit.collider.gameObject.GetComponent <Transform>();
                    move.controller.enabled = false;
                    playerBody.position     = obj.position;
                    isSit       = true;
                    move.notrun = true;
                }
            }

            if (hit.collider.gameObject.CompareTag("music"))
            {
                if (Input.GetMouseButtonDown(0) && isPlaying)
                {
                    audioSource = hit.collider.GetComponent <AudioSource>();
                    audioSource.Stop();
                    isPlaying = false;
                    activeObj[0].SetActive(true);
                }

                else if (Input.GetMouseButtonDown(0) && !isPlaying)
                {
                    audioSource = hit.collider.GetComponent <AudioSource>();
                    audioSource.Play();
                    isPlaying = true;
                }
            }



            if (hit.collider.gameObject.CompareTag("lock"))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    lockedText.text = "Door is locked!";
                    StartCoroutine(disableText());
                }
            }

            if (hit.collider.gameObject.CompareTag("key"))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    lockedText.text = "You pickup a key!";
                    StartCoroutine(disableText());
                    Destroy(hit.collider.gameObject);
                }
            }

            if (hit.collider.gameObject.CompareTag("blanket"))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    animator = hit.collider.gameObject.GetComponent <Animator>();
                    animator.SetBool("open", true);
                }
            }

            if (hit.collider.gameObject.CompareTag("lantern"))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    Destroy(hit.collider.gameObject);
                    lantern.SetActive(true);
                    guncam.depth    = 80;
                    lockedText.text = "You got a lantern!";
                    StartCoroutine(disableText());
                }
            }
        }
    }