public Sprite imgS; //先创建个Sprite 设置上图片
// 创建GameObject对象
GameObject gameObj = new GameObject();
// 获取SpriteRenderer对象
SpriteRenderer spr = gameObj.AddComponent(typeof(SpriteRenderer)) as SpriteRenderer;
// 添加图片 把上面的sprite赋值给他
spr.sprite = imgS; // Resources.Load("triangle.png", typeof(Sprite)) as Sprite;
// 设置位置
spr.transform.position = new Vector2(x, y);
网友评论