Question by
nekosune · Sep 03, 2017 at 05:43 PM ·
scripting problemui image
Image to show icon works on one scene but not the other.
I am trying to show an icon on the UI when the player is looking at an enemy. The raycasting code, etc all works, but on one scene, the icon shows successfully, the other, it doesn't. I have tried copying, recreating, using different Sprites, none of it works.
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CursorAffordance : MonoBehaviour
{
[SerializeField] private Sprite _combatAffordance;
private CameraRaycaster _raycaster;
private Image _image;
// Use this for initialization
void Start ()
{
_raycaster = FindObjectOfType<CameraRaycaster>();
_image = FindObjectOfType<Image>();
}
// Update is called once per frame
void LateUpdate () {
if (Input.GetMouseButton(0))
{
print(_raycaster.layerHit);
}
switch (_raycaster.layerHit)
{
case Layer.Enemy:
_image.sprite = _combatAffordance;
_image.enabled = true;
break;
default:
_image.sprite = null;
_image.enabled = false;
break;
}
}
}
The only thing i can find from debugging is _combatAffordance is somehow null the second run through , and stays null from then on, although in inspetor it still shows my Target sprite.
Comment
Your answer
Follow this Question
Related Questions
Trigger GUI elements 1 Answer
UnityEngine.UI and UnityEngine.EventSystem do not work, what do I do? 1 Answer
Using downloaded image as UI Image's source image? 1 Answer
Coroutine wont start 0 Answers