Oops, I wasn't creating the Canvas. I'll leave this up in case anyone else missed this! Thanks!
Booper
9
Posts
1
Topics
1
Followers
A member registered Aug 07, 2016 · View creator page →
Recent community posts
Thanks for hosting this jam! Any chance you could share the .cs files from the tutorial? Or if you could point me in the right direction, it would be much appreciated. I'm getting a null reference exception in Interactor for:
if (interactImage.sprite != defaultIcon)
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Interactor : MonoBehaviour { public LayerMask interactableLayermask = 8; public Interactable interactable; public Image interactImage; public Sprite defaultIcon; public Vector2 defaultIconSize; public Sprite defaultInteractIcon; public Vector2 defaultInteractIconSize; // Start is called before the first frame update void Start() { } // Update is called once per frame void Update() { RaycastHit hit; if (Physics.Raycast(Camera.main.transform.position, Camera.main.transform.forward, out hit, 2, interactableLayermask)) { if (hit.collider.GetComponent<Interactable>() != false) { if (interactable == null || interactable.ID != hit.collider.GetComponent<Interactable>().ID) { interactable = hit.collider.GetComponent<Interactable>(); } if (interactable.interactIcon != null) { interactImage.sprite = interactable.interactIcon; if (interactable.iconSize == Vector2.zero) { interactImage.rectTransform.sizeDelta = defaultInteractIconSize; } else { interactImage.rectTransform.sizeDelta = interactable.iconSize; } } else { interactImage.sprite = defaultInteractIcon; interactImage.rectTransform.sizeDelta = defaultInteractIconSize; } if (Input.GetKeyDown(KeyCode.E)) { interactable.onInteract.Invoke(); } } } else { if (interactImage.sprite != defaultIcon) { interactImage.sprite = defaultIcon; interactImage.rectTransform.sizeDelta = defaultIconSize; } } } }