I created this very basic script so I could easily add Rectangles to my game, but for some reason when I run the game the rectangles give me the following errors:
rd->texture.IsValid()
And
rd->texture.IsValid()
UnityEditor.DockArea:OnGUI()
The rectangles display and work fine during gameplay, so why am I getting these errors?
using UnityEngine;
using UnityEditor;
using System.Collections;
public class CreateSprite : MonoBehaviour {
[MenuItem("GameObject/2D Object/Rectangle")]
static void CreateRectangle(){
GameObject obj = new GameObject("Rectangle");
SpriteRenderer spr = obj.AddComponent<SpriteRenderer>();
BoxCollider2D bx = obj.AddComponent<BoxCollider2D>();
bx.size = new Vector2(1f, 1f);
Texture2D texture = Texture2D.whiteTexture;
Sprite sprite = Sprite.Create(texture, new Rect(0, 0, 100f, 100f), new Vector2(.5f, .5f), 100f);
sprite.name = "Rectangle";
spr.sprite = sprite;
}
}