• 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
Question by helloiam · Nov 17, 2012 at 03:25 PM · gameguitextureitem

Show GUITexture by picking an item.

Dear people,

I made a few GUITextures in Unity3D and when I run the game, it shows my Textures well. What I want is when I collect an item, then I want the texture to show on the screen.

(as example when I pickup 1 item, it shows GUITexture Hello1, but if I pickup 2 items (when the system counts 2, it's scripted, the foundGems++ as you can see in the script below) it shows GUITexture Hello2 and so on)

So in my collecting script I want to do as follow,

  • If I collect a item, it shows a texture and right before the destroy method (where the item disappear) it must not show the texture anymore.

My script:

 using UnityEngine;
 using System.Collections;
 
 public enum MarbleGameState {playing, won,lost };
 
 public class MarbleGameManager : MonoBehaviour
 {
     public static MarbleGameManager SP;
 
     private int totalGems;
     private int foundGems;
     private MarbleGameState gameState;
     
     **public GUITexture FoundGem1;**
     
     public AudioSource Lose;
     public AudioSource Win;
     
     public bool Show = false;
     
 
     **void Start () {
     
         FoundGem1.enabled = false;
     }**
     
     void Awake()
     {
         SP = this; 
         **foundGems = 0;**
         gameState = MarbleGameState.playing;
         totalGems = GameObject.FindGameObjectsWithTag("Pickup").Length;
         Time.timeScale = 1.0f;
     }
     
     **void Update()
     {
         if(foundGems == 1)
         {
             FoundGem1.enabled = true;
         }
     }**
 
     void OnGUI () {
         GUILayout.Label(" Found gems: "+foundGems+"/"+totalGems );
         
         if (gameState == MarbleGameState.lost)
         {
             GUILayout.Label("You Lost!");
             if(GUILayout.Button("Try again") ){
                 Application.LoadLevel(Application.loadedLevel);
             }
         }
         else if (gameState == MarbleGameState.won)
         {
             GUILayout.Label("You won!");
             if(GUILayout.Button("Play again") ){
                 Application.LoadLevel(Application.loadedLevel);
             }
         }
     }
 
     **public void FoundGem()
     {            
         foundGems++;
         
         if (foundGems >= totalGems)
         {
             WonGame();
         }
     }**
 
     public void WonGame()
     {
         Win.Play();
         Time.timeScale = 0.0f;
         gameState = MarbleGameState.won;
     }
 
     public void SetGameOver()
     {
         Show = true;
         Lose.Play();
         Time.timeScale = 0.0f;
         gameState = MarbleGameState.lost;
     }
     
 }


It's about the GUITexture FoundGem1; I made it public, to just drag and drop the GUItexture in it. I want when foundGems == 1, then enabled = true.

And in my other script:

 using UnityEngine;
 using System.Collections;
 
 public class MarbleControl : MonoBehaviour {
 
     public float movementSpeed = 6.0f;
     public AudioSource Gem;
     
     void Update () {
         Vector3 movement = (Input.GetAxis("Horizontal") * -Vector3.left * movementSpeed) + (Input.GetAxis("Vertical") * Vector3.forward * movementSpeed);
         rigidbody.AddForce(movement, ForceMode.Force);
     }
 
     void OnTriggerEnter  (Collider other) {
         if (other.tag == "Pickup")
         {
             Gem.Play();
             MarbleGameManager.SP.FoundGem();
             **// Right here it must not show the texture anymore, if u understand what                I mean.**
             Destroy(other.gameObject);
         }   
     }
 
 }

When item is being destroyed I want right before it, that the GUITexture = enabled to false, so it doesn't shows it anymore. I want to do this for many more Texture I have created, I have a win texture and lose texture.

So if anybody can give my a clear answer or with explanation. I would be very gratefull.

Kind regards,

helloiam.

Comment

People who like this

0 Show 0
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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

Torch Durabillity? 2 Answers

Pause Menu 5 Answers

Problem vid GuiTexture 0 Answers

Problem with BRDF Shader 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