- Home /
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.
Your answer
Follow this Question
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