Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- //InteractObject.cs
- public abstract class InteractObject : MonoBehaviour
- {
- public abstract void OnPlayerInterect(GameObject player);
- }
- //InteractDoor.cs
- public class InteractDoor : InteractObject
- {
- bool Open;
- public override void OnPlayerInterect(GameObject player)
- {
- this.Open = !this.Open;
- }
- }
- //PlayerInterect.cs
- public class PlayerInterect : MonoBehaviour
- {
- //Layer object detecte
- [SerializeField] LayerMask layerMask;
- [SerializeField] float InterectDistance = 1.2f;
- void Update()
- {
- if (Input.GetKeyDown(KeyCode.E)) {
- RaycastHit hit;
- if (Physics.Raycast(transform.position,
- transform.TransformDirection(Vector3.forward), out hit,
- InterectDistance, layerMask))
- {
- InteractObject interactObj =
- hit.transform.GetComponent<InteractObject>();
- if (interactObj)
- {
- interactObj.OnPlayerInterect(this.gameObject);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment