- Home /
Cursor is showing up as pink rectangle?
So Im trying to make a script to animate my cursor (not a mouse cursor) also, im not using Gui Components at all. basically i have 32 different materials that are basically acting as a sprite sheet for this cursor. and if the cursor is over something selectable, it will change the material of the cursor 32 times over the course of 2 seconds. I havent added the Time.deltaTime stuff yet because now every time i play my game, the cursor just shows up as a pink rectangle, which im assuming means it has no material attached to it whatsoever. heres my code
using UnityEngine;
using System.Collections;
public class CursorAnimation : MonoBehaviour {
public Texture2D txCursor;
static Material c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17,
c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32;
Material[] c_array = new Material[]{c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13, c14, c15, c16, c17, c18, c19, c20, c21, c22, c23, c24, c25, c26, c27, c28, c29, c30, c31, c32};
void Start()
{
c0 = Resources.Load ("mat_reticle", typeof(Material)) as Material;
c1 = Resources.Load ("mat_c1", typeof(Material)) as Material;
c2 = Resources.Load ("mat_c2", typeof(Material)) as Material;
c3 = Resources.Load ("mat_c3", typeof(Material)) as Material;
c4 = Resources.Load ("mat_c4", typeof(Material)) as Material;
c5 = Resources.Load ("mat_c5", typeof(Material)) as Material;
c6 = Resources.Load ("mat_c6", typeof(Material)) as Material;
c7 = Resources.Load ("mat_c7", typeof(Material)) as Material;
c8 = Resources.Load ("mat_c8", typeof(Material)) as Material;
c9 = Resources.Load ("mat_9", typeof(Material)) as Material;
c10 = Resources.Load ("mat_c10", typeof(Material)) as Material;
c11 = Resources.Load ("mat_c11", typeof(Material)) as Material;
c12 = Resources.Load ("mat_c12", typeof(Material)) as Material;
c13 = Resources.Load ("mat_c13", typeof(Material)) as Material;
c14 = Resources.Load ("mat_c14", typeof(Material)) as Material;
c15 = Resources.Load ("mat_c15", typeof(Material)) as Material;
c16 = Resources.Load ("mat_c16", typeof(Material)) as Material;
c17 = Resources.Load ("mat_c17", typeof(Material)) as Material;
c18 = Resources.Load ("mat_c18", typeof(Material)) as Material;
c19 = Resources.Load ("mat_c19", typeof(Material)) as Material;
c20 = Resources.Load ("mat_c20", typeof(Material)) as Material;
c21 = Resources.Load ("mat_c21", typeof(Material)) as Material;
c22 = Resources.Load ("mat_c22", typeof(Material)) as Material;
c23 = Resources.Load ("mat_c23", typeof(Material)) as Material;
c24 = Resources.Load ("mat_c24", typeof(Material)) as Material;
c25 = Resources.Load ("mat_c25", typeof(Material)) as Material;
c26 = Resources.Load ("mat_c26", typeof(Material)) as Material;
c27 = Resources.Load ("mat_c27", typeof(Material)) as Material;
c28 = Resources.Load ("mat_c28", typeof(Material)) as Material;
c29 = Resources.Load ("mat_c29", typeof(Material)) as Material;
c30 = Resources.Load ("mat_c30", typeof(Material)) as Material;
c31 = Resources.Load ("mat_c31", typeof(Material)) as Material;
c32 = Resources.Load ("mat_c32", typeof(Material)) as Material;
}
public void animateCursor()
{
int spot = 0;
for (int x = 0; x < c_array.Length; x++){
GetComponent<Renderer> ().material = c_array [spot];
spot ++;
}
if (spot >= c_array.Length)
spot = 0;
}
}
Answer by GiyomuGames · Jun 29, 2015 at 04:41 AM
What you are doing seems very strange. If you are trying to have an animation on the cursor why don't you use an animation instead of changing the material like you do? You can create an animation on your cursor which will change the sprite 32 times during 2 seconds (using only 1 material on your sprite).
But to answer your question, if you cursor is a pink rectangle then there must be a problem with the shader of your materials.
I know it is, but ive never used animations in unity before, i dodnt really think.about it while i was doing it
Your answer
![](https://koobas.hobune.stream/wayback/20220613201515im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Can I make animations snap to a frame? 1 Answer
Why are materials on diffuse pink? 0 Answers
Animate a river in Unity 2 Answers