Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PlayerMovement : MonoBehaviour {
- public Interactable focus;
- // Use this for initialization
- void Start () {
- }
- // Update is called once per frame
- void Update () {
- if (Input.GetButton("Fire1"))
- {
- //create a ray
- Ray ray = Camera.main.ViewportPointToRay(Vector3.one / 2f);
- Debug.DrawRay(ray.origin, ray.direction * 2f, Color.red);
- RaycastHit hitInfo;
- //If the ray hits
- if(Physics.Raycast(ray, out hitInfo, 2f))
- {
- Interactable interactable = hitInfo.collider.GetComponent<Interactable>();
- //Check if we hit Interactable
- if (interactable != null)
- {
- SetFocus(interactable);
- }
- }
- }
- else
- {
- RemoveFocus();
- }
- }
- private void SetFocus(Interactable newFocus)
- {
- focus = newFocus;
- }
- private void RemoveFocus()
- {
- focus = null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement