rendere.enabled and collider. enabled not working on more than one game object

I have a simple script attached to 3d texts, which display some game over text, the operation is simple, i wish to hide whilst the game is running then show when its at game over.Whilst the game runs none of the items i have this script attached to shows however when it actually is game over only one item shows, ive checked that the script is attahced to the given object and still no luck, it will only ever work for one single item, why is this

using UnityEngine;
using System.Collections;

public class GameOver : MonoBehaviour {
	public GameObject text;
	Vector3 myOldSize;
	// Use this for initialization
	void Start () {
		text=this.gameObject;
		Debug.Log(text.name);
		Hide ();
		
		
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	public void show()
	{
		Debug.Log ("called");
		this.renderer.enabled=true;
		this.collider.enabled=true;
	}
	void Hide(){
		this.renderer.enabled=false;
		this.collider.enabled=false;
	}
	
	/*
	void OnCollisionStay(Collision Other){
		if(Other.gameObject.name==("Cursor_prefab")){
			
			
			
		}*/
		
	}

which one shows and what code calls show? it's usually best to first assume that Unity's code works

The list of guitextures are Exit, Game Over, High Score and Main menu. In that precise order, the one that shows is the Exit @Louis

2 Answers

2

You never call your show() function, that’s why.

Regards BPR

Sorry i forgot to add, i call my show method from a diffrenet class via broadcasting the method, even if that were the case then essentially none should show rather than just one game object @BPR

hm what method do you use to find the text objects? Does the Debug.Log message show up?

Presumably this script is attached to each of the text objects that you wish to enable and not just one of them?

@cassius indeed ive deleted every objecct added new ones and it only shows or hides the one element, and @BPR the debug brings back the name of each object its attached to

@skyerz Any chance we can have a peek at the source performing the broadcast? I assume that your Show()'s Debug.Log message is also not output more than once either.

It appears that what you want to do is get an array of items to broadcast to but haven’t actually used an array in your code that starts the Broadcast. Based on your comment above, I think your other code needs to look more like this…

Sorry for the sudo code in Game_Over(). I develop in UnityScript/javascript…

GameState game;
// Use this for initialization
// NOTE: The 'g' variable will need to be changed to an array
void Start () {
    countDown = 60;
    bloodEffect = (BloodOnScreen)FindObjectOfType(typeof(BloodOnScreen));
    GameOver[] g = FindObjectsOfType(typeof(GameOver)) as GameOver[];
}

void Game_Over(){
    foreach(GameOver gameover in g) {
         gameover.BroadcastMessage("Show");
    }
    roundedRestSeconds=0;
    running=false;
    gOver=true;
}

Hope that helps.

i think this might be the answer, would it then mean that g will have to be a game object. At the present moment its GameOver g =(GameOver)FindObjectOftype(typeof(GameOver)) @cassius

@skyerz You should be able to still typecast it as type GameOver. I don't know C# but perhaps it would look something to this? GameOver[] g = FindObjectsOfType(typeof(GameOver)) as GameOver[]; // Or maybe g = FindObjectsOfType(typeof(GameOver)) as GameOver[]; and then... foreach (GameOver gameover in g) { gameover.BroadcastMessage("Show"); }

I believe it would be game objects simply because GameOver is the essentially refereing to the script. It doesnt seem logical to have an array of scripts however your answer is correct and it now works, instead of game over it would be game objects, and you assign each object in the inspector Thank you @cassius

Glad its working for you! :)