Hello, i hope someone can help me.
This is how i load my menu :
`
public GameObject cadrebat;
public Sprite[ ] racebat;
void Start()
{
racebat = Resources.LoadAll(“humanbat/”);
for (int i = 0; i < racebat.Length; i++)
{
menu.Add(Instantiate(cadrebat, gameObject.transform));
menu_.GetComponent().sprite = racebat*;_
_}_
_}_
_`*_
the script is loading on a specific object with a layout for it’s positioning so here what i get once loaded, perfect in scene, wrong in game…
i can’t use an image because the game object cadrebat already got one, i’m just trying to modify the sprite, and it’s works in scene but not in game i’m lost here help plz.
_*here is a screenshot of my screens : http://www.hostingpics.net/viewer.php?id=572827helpUnity.jpg*_
you can see the 3 instantiated game object, all their component. with the sprite on the right in the scene, without on the left in the game…
Could that be i’m trying to use a sprite renderer with a Texture2D type in a 3D world ?? or it doesn’t matter since it’s in the 2D overlay of the canvas ?
Okai i was 100% wrong as i though it couldn’t be the overlay but in fact it is 100% the overlay, you have to play with camera setting and layer to display correctly i didn’t do it i tryed and failed, i just remade the source image so i don’t have to display a sprite… if anyone know a better way to display sprite through overlay i’m all ears.
thx anyway, peace.
come back to give the code in case anyone wants it with a free auto update name for latter scaling ^^
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using UnityEngine.UI;
public class uibatimenselec : MonoBehaviour {
public GameObject cadrebat;
Sprite[ ] racebat;
List menu;
void Start()
{
racebat = Resources.LoadAll(“humanbat/”);
foreach (var n in racebat)
{
}
for (int i = 0; i < racebat.Length; i++)
{
menu.Add(Instantiate(cadrebat, gameObject.transform));
menu_.GetComponent().sprite = racebat*;_
_}_
_}_
_}*_
and attach this one to the text of the prefab (in this case GameObject cadrebat) and use the name of the file to auto rename your button.
using UnityEngine;
using UnityEngine.UI;
public class TextNomBat : MonoBehaviour {
void Start () {
GetComponent().text = GetComponentInParent().sprite.name;
}
Please edit your post, don’t do 4 back to back posts in the same day?
Basics of any forum, not just this one.