- Home /
IpointerClick Interface Error
Hello I have this error that I don't understand since I never used interfaces and would like too understand how I may get rid of the error. I have this script which handles all my Hud stuff of my player where you cycle through different ability's through buttons using the UGUI, but if I go out of index range I get an error.Type IPointerClickHandler expected Button received. i:0. Array index is out of range. UnityEngine.EventSystems.EventSystem:Update().Some Insight on how to solve this would be appreciated.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class PlayerHud : MonoBehaviour,IPointerClickHandler
{
public Sprite[] UIProjectileSprites;
public Image SpriteImage;
public Text Ammo;
public Image PowerImage;
public GameObject EnemyInfoCanvas;
public Text EnemyName;
public Text EnemyLife;
public Text EnemyShipClassType;
private GameObject PowerTransform;
private PlayerShipFire PSF;
public Animator Anim;
[HideInInspector]
public int UISpriteIndex;
// Use this for initialization
void Start ()
{
SetUpRefernaces();
PSF.ProjectileIndex = UISpriteIndex;
UISpriteIndex = UIProjectileSprites.Length;
Debug.Log(UIProjectileSprites[PSF.ProjectileIndex].ToString());
}
private void SetUpRefernaces()
{
PSF = GetComponent<PlayerShipFire>();
PowerTransform = GameObject.Find("PowerImage");
PowerImage = PowerTransform.GetComponent<Image>();
}
public void IncrementProjectileIndex()
{
UISpriteIndex ++;
SpriteImage.sprite = UIProjectileSprites[UISpriteIndex];
PSF.ProjectileIndex++;
print (PSF.ShipProjectiles[PSF.ProjectileIndex].name);
Debug.Log(UISpriteIndex);
}
public void decrementProjectileIndex()
{
UISpriteIndex --;
SpriteImage.sprite = UIProjectileSprites[UISpriteIndex];
PSF.ProjectileIndex++;
print (PSF.ShipProjectiles[PSF.ProjectileIndex].name);
Debug.Log(UISpriteIndex);
}
public void OnPointerClick(PointerEventData Data)
{
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613163918im_/https://answers.unity.com/themes/thub/images/avi.jpg)