forked from SamMorey/GameArchitectureCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteractable.cs
34 lines (31 loc) · 991 Bytes
/
Interactable.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Interactable : MonoBehaviour
{
[SerializeField] Material _nonInteractable;
[SerializeField] Material _Interactable;
[SerializeField] float _maxDistance = 10f;
[SerializeField] LayerMask _layerMask;
[SerializeField] List<GameEvent> _gameEventToInvoke = new List<GameEvent>();
Camera mainCamera;
void Start()
{
mainCamera = Camera.main;
}
void Update()
{
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, _maxDistance, _layerMask))
{
if (Input.GetKey(KeyCode.F))
{
MeshRenderer meshRenderer = hit.transform.GetComponent<MeshRenderer>();
meshRenderer.materials = new Material[] {_Interactable};
GameEvent.RaiseEvent(_gameEventToInvoke);
}
}
}
}