Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by NeoStarGames · May 01, 2017 at 01:03 PM · 2dshadershaderscanvasarrays

Changing images using a shader on a 2D canvas?

I'm trying to create a character select screen that uses a single square for each player and takes controller input to scroll through an array of images to select the character they want. I have most of it down. The trouble is that while the shader on the square reflects the image I want to see in the inspector, the image in the actual game doesn't change unless I toggle something in the shader inspector!

Here is my code, which includes the array for the actual fighter select.

 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.EventSystems;
 
 public class FighterSelection : MonoBehaviour {
 
     public int index = 0;
     public bool caninteract;
     public string Horiz;
     public string Vert;
     public string fighterfolder;
     public string P;
     public GameObject Im;
     public List<GameObject> fighterlist;
     public List<Texture> plist;
     public string TextureName;
 
     void Start (){ 
         
         caninteract = true;
         Texture[] pics = Resources.LoadAll<Texture> ("Images/Portraits");
         GameObject[] fighter = Resources.LoadAll<GameObject>(fighterfolder);
 
         foreach (GameObject f in fighter) {
             GameObject fightr = Instantiate(f) as GameObject;
             fightr.transform.SetParent(GameObject.Find(P).transform);
 
             fighterlist.Add (fightr);
             fightr.SetActive (false);
             fighterlist [index].SetActive (true);
 
             foreach (Texture i in pics) {
                 Texture pc = Instantiate (i) as Texture;
                 plist.Add (pc);
 
             }
         }
     }
     void Update(){
 
         if (caninteract == true);
         {
             if (Input.GetAxis (Horiz) > 0f) {
                 ToggleRight ();
                 StartCoroutine (select ());
                 }
             if (Input.GetAxis (Horiz) < 0f) {
                 ToggleLeft ();
                 StartCoroutine (select ());
             } 
         } 
 
         Texture portrait = (Texture)plist [index];
         Im.GetComponent<Image> ().material.mainTexture = portrait;
         Im.GetComponent<Image> ().material.SetColor ("_Color", Color.clear);
     }
         IEnumerator select ()
     {
         yield return new WaitForSeconds (0.75f);
         caninteract = true;
     }
 
     public void ToggleLeft()
     {
         fighterlist [index].SetActive (false);
         index --;
         caninteract = false;
         if (index < 0) {
             index = fighterlist.Count - 1;
         }
             fighterlist [index].SetActive (true);
     } 
     public void ToggleRight ()
     {
         fighterlist[index].SetActive (false);
         index++;
         caninteract = false;
         if (index == fighterlist.Count) {
             index = 0;
         }
             fighterlist [index].SetActive (true);
     } 
 }

The variables I put in the inspector are to separate the script by player. I also have a problem getting the waitforseconds thing to work, but that can wait. What am I doing wrong?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Sprite Shader not working in 5.6 0 Answers

Blending 2d light sprites 1 Answer

How to do 2D graphics like this ? 1 Answer

I Installed URP But I Can't Create 2D Shaders 1 Answer

Replicate CSS3 animation in Unity 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges