- Home /
I'm trying to make a button change two images at once?
Let me just start by saying I am absolutely a noob to code~! Okay, so I'm using this code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Facepicker : MonoBehaviour {
public SpriteRenderer part;
public Sprite[] options;
public int index;
void Update(){
for (int i = 0; i < options.Length; i++) {
if(i == index){
part.sprite = options[i];
}
}
}
public void Swap(){
if (index < options.Length - 1){
index++;
} else{
index = 0;
}
}
}
I tried duplicating it in the inspector and using the duplicate for the cat face icon to change when the body type does, but it just doesn't change. :(
Answer by LeeroyLin · Jun 22, 2018 at 05:23 AM
Duplicating may not work. If there are two same scripts on an object, when you click the button, it can only execute one of them. You can put two Facepicker scripts into two different objects, even the Skogkat button, and Skogkatt. Finally, you have to make sure the OnClick event has been set to both "Swap" function in the script at the button. Any question can comment, good day.
Your answer
Follow this Question
Related Questions
How to get exact button input 4 Answers
how to load images from hard disk to gui buttons? 1 Answer
Clickable button area is offset 0 Answers
How to make UI buttons so my player can move along certain lines 0 Answers
how do i make my button's source image bigger without changing the button hover/clickable area? 0 Answers