Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 TakMarche · Oct 02, 2012 at 08:15 AM · c#guivaluespassing

Passing More Then One Int Into Another Script As A GUI

I have a simple CubeManager script the allows me to set a certain cube into a CubeType, each with it's very own unique number from 0 - 9. What I'm trying to figure out and do is that when a cube is selected it would pass it's number value into another script to display as a GUI. How should I go about doing this? If I am correct the default cNumber way I set it up would cause confusing when passing numbers. (I have 10 cubes in my scene using the same script).

 using UnityEngine;
 using System.Collections;
 
 public class CubeManager : MonoBehaviour {
     
     public enum CubeType {cubeZero, cubeOne, cubeTwo, cubeThree, cubeFour, cubeFive, cubeSix,cubeSeven, cubeEight, cubeNine}
     
     public CubeType cubeNumType;
     public bool cubeClick = false;
     public int cNumber;
     public static int guiNum;
     
     public Material matCubeZero;
     public Material matCubeOne;
     public Material matCubeTwo;
     public Material matCubeThree;
     public Material matCubeFour;
     public Material matCubeFive;
     public Material matCubeSix;
     public Material matCubeSeven;
     public Material matCubeEight;
     public Material matCubeNine;
 
     void Start ()
     {
         CubeNum();
     }
     
     void Update ()
     {
         
         if(cubeClick)
         {
             renderer.material.color = Color.green;
             print (cNumber);
         }
         else
         {
             renderer.material.color = Color.white;    
         }
     }
     
     public void CubeNum()
     {
         switch (cubeNumType)
         {
             case CubeType.cubeZero:
                 renderer.material = matCubeZero;
                 cNumber = 0;
                 guiNum = cNumber;
                 PlayerPrefs.GetInt("Number0", guiNum);
                 break;
             case CubeType.cubeOne:
                 renderer.material = matCubeOne;
                 guiNum = cNumber;
                 PlayerPrefs.GetInt("Number1", guiNum);
                 cNumber = 1;
                 break;
             case CubeType.cubeTwo:
                 renderer.material = matCubeTwo;
                 cNumber = 2;
                 break;
             case CubeType.cubeThree:
                 renderer.material = matCubeThree;
                 cNumber = 3;
                 break;
             case CubeType.cubeFour:
                 renderer.material = matCubeFour;
                 cNumber = 4;
                 break; 
             case CubeType.cubeFive:
                 renderer.material = matCubeFive;
                 cNumber = 5;
                 break;
             case CubeType.cubeSix:
                 renderer.material = matCubeSix;
                 cNumber = 6;
                 break;
             case CubeType.cubeSeven:
                 renderer.material = matCubeSeven;
                 cNumber = 7;
                 break;
             case CubeType.cubeEight:
                 renderer.material = matCubeEight;
                 cNumber = 8;
                 break;
             case CubeType.cubeNine:
                 renderer.material = matCubeNine;
                 cNumber = 9;
                 break;
         }    
     }
 }
 
Comment
Add comment · Show 1
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
avatar image Fattie · Oct 02, 2012 at 09:23 AM 0
Share

you really need to learn how to use List or at least an array.

there is an incredible, astounding amount of lessons, material, documentation, tutorials and so on regarding how to access scripts on other objects, components. There must be 100s of pages on the internet regarding the issue, and 1,000s of questions here.

read all of this:

http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

http://docs.unity3d.com/Documentation/ScriptReference/index.Accessing_Other_Components.html

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

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Values not moving to Game Over screen or the Game over doesn't somehow work. 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

NullreferenceException, BeginScrollView style change 3 Answers

Scaled GUI 1 Answer


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