Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PlayerController : NetworkBehaviour
- {
- public override void OnStartClient()
- {
- base.OnStartClient();
- if (!base.IsOwner)
- {
- GetComponent<PlayerController>().enabled = false;
- }
- ConfigureCharacter();
- }
- // Update is called once per frame
- void Update()
- {
- // Interact with interactable object
- if (Input.GetKeyDown(KeyCode.E))
- {
- Interact();
- }
- }
- private void Interact()
- {
- // If there's an interactable object, interact with it
- if (interactableObject == null)
- {
- LogManager.Instance.Log("There's nothing to interact with!");
- return;
- }
- interactableObject.Interact(gameObject);
- }
- }
Advertisement
Comments
-
- private void OnTriggerEnter2D(Collider2D collision)
- {
- // Get x/y values for movement if the character isn't colliding with anything
- if (!base.IsOwner)
- {
- return;
- }
- // Check if the collided object is interactable
- IInteractable interactableObjectColliding = collision.GetComponent<IInteractable>();
- if (interactableObjectColliding != null)
- {
- interactableObjectName = collision.gameObject.name;
- interactableObject = collision.GetComponent<IInteractable>();
- LogManager.Instance.Log($"{gameObject.name} is near {interactableObjectName}");
- }
- }
- private void OnTriggerExit2D(Collider2D collision)
- {
- // Get x/y values for movement if the character isn't colliding with anything
- if (!base.IsOwner)
- {
- return;
- }
- // Check if the collided object is interactable
- IInteractable interactableObjectColliding = collision.GetComponent<IInteractable>();
- if (interactableObjectColliding != null)
- {
- LogManager.Instance.Log($"{gameObject.name} is no longer near {interactableObjectName}");
- interactableObjectName = null;
- interactableObject = null;
- }
- }
Add Comment
Please, Sign In to add comment