Author Topic: Changing Sprite textures with script  (Read 3889 times)

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Changing Sprite textures with script
« on: May 03, 2013, 12:53:32 PM »
Hey! I Finally almost finished my menu, but I ran into a problem. I'm trying to change sprite on Popup-list selection change. I haven't found any tutorials, so I made this post. This is my code right now (As you may know from my previous posts, I really suck at coding):
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class Pokemon : MonoBehaviour {
  6.    
  7.     public List<string> Starters;
  8.     public string pokeInt;
  9.         public UISprite BulbasaurIcon;
  10.    
  11.     // Use this for initialization
  12.     void Start () {
  13.             Starters.Add("Bulbasaur");
  14.                     Starters.Add("Charmander");
  15.                     Starters.Add("Squirtle");
  16.     }
  17.    
  18.     // Update is called once per frame
  19.     void Update () {
  20.    
  21.     }
  22.    
  23.     public void OnSelectionChange(string mSelectedItem) {
  24.         if(Starters.Contains(mSelectedItem)) {
  25.             Debug.Log("Changing Starter");
  26.             pokeInt = mSelectedItem;
  27.             BulbasaurIcon.spriteName = pokeInt;
  28.         }
  29.     }
  30. }
!!!This isn't completely my code. I just edited the code, I'm using to change Graphic Quality!!!
(and yes, I'm making a pokemon game :P)
This code doesn't show any error, but it either doesn't work, or I'm putting it onto wrong object...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Changing Sprite textures with script
« Reply #1 on: May 03, 2013, 09:45:25 PM »
Haven't found any tutorials? As I recall the popup list tutorial shows you how to switch a sprite's color based on selection. Switching a sprite is exactly the same -- except adjusting spriteName.

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Changing Sprite textures with script
« Reply #2 on: May 04, 2013, 04:47:04 AM »
Oh lol. I have overlooked that... Thanks.