- Home /
This question was
closed Mar 09, 2017 at 08:34 AM by
lupelipcuro for the following reason:
I found the problem :D
Question by
lupelipcuro · Mar 10, 2017 at 07:13 AM ·
spriteimagesprite renderer
SpriteRenderer doesn't show the sprite
Hi I'm trying to change the image of the sprite when I press some letter, this is my code
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class juegodiferencias : MonoBehaviour {
public GameObject Canvas;
public GameObject Panel;
public GameObject ImagenCambiante;
public GameObject createImage;
public string random;
public char ascii;
public string rletra;
// Use this for initialization
void Start () {
createImage = Instantiate(ImagenCambiante, new Vector3 (0, 0, -1), new Quaternion (0,0,0,1)) as GameObject;
createImage.transform.SetParent (Panel.transform, false);
Panel.transform.SetParent (Canvas.transform, false);
random = Random.Range (1, 6).ToString();
ascii = (char)Random.Range (97, 99);
rletra = ascii.ToString ();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown ("space")) {
createImage.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite> ("Sprites/"+random+"/"+random);
}
if (Input.GetKeyDown ("w")) {
createImage.GetComponent<SpriteRenderer>().sprite = Resources.Load<Sprite> ("Sprites/"+random+"/"+random+rletra);
}
}
}
When I press the letters nothing appears but in the preview board it could see that the sprite was assigned
Thank you for your help.
2017-03-09.png
(222.1 kB)
Comment
Follow this Question
Related Questions
maintextureoffset on sprite renderer 1 Answer
Error facebook profile picture 1 Answer
Crop UI image and convert it as Sprite 1 Answer