Continue work on spelling bee
This commit is contained in:
@@ -2,23 +2,49 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SpellingBeeController : MonoBehaviour
|
||||
{
|
||||
private string[] words;
|
||||
public Image image;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start() {
|
||||
TextAsset textFile = Resources.Load<TextAsset>("SpellingBee/words");
|
||||
string fileContents = textFile.text;
|
||||
|
||||
words = fileContents.Split('\n');
|
||||
words = fileContents.Split('\n');
|
||||
Image imageComponent = image.GetComponent<Image>();
|
||||
|
||||
// Load the new sprite from the Resources folder
|
||||
Debug.Log("SpellingBee/images/" + "monke");
|
||||
Sprite sprite = Resources.Load<Sprite>("SpellingBee/images/monke");
|
||||
image.sprite = sprite;
|
||||
Debug.Log(sprite.pixelsPerUnit);
|
||||
//changeSprite("monke");
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update() {
|
||||
|
||||
int randomIndex = UnityEngine.Random.Range(0, words.Length - 1);
|
||||
string randomWord = words[randomIndex];
|
||||
|
||||
changeSprite(randomWord);
|
||||
|
||||
Debug.Log(randomWord);
|
||||
|
||||
}
|
||||
|
||||
void changeSprite(string spriteName) {
|
||||
Image imageComponent = image.GetComponent<Image>();
|
||||
|
||||
// Load the new sprite from the Resources folder
|
||||
Debug.Log("SpellingBee/images/" + spriteName);
|
||||
Sprite sprite = Resources.Load<Sprite>("SpellingBee/images/" + spriteName);
|
||||
Debug.Log(sprite.pixelsPerUnit);
|
||||
// Set the new sprite as the Image component's source image
|
||||
image.sprite = sprite;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user