[c#] OnGui is rendered on all cameras

hey. my OnGUI code is renered on all cameras still it not even attached to the Prefab or GameObject

Code:

using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour {
	
	public int maxHealth = 100;
	public int curHealth = 100;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	}
	
	private void OnGUI () {
		
		GUI.Box (new Rect( 450, 570, Screen.width / 3, 20), curHealth + "/" + maxHealth);
	}
}

i will have it to render only the object is attached to.

exsample.

2 objects have is attached to. its a dupplicated

i will have it to.

it not showing the other players health.

1 Answer

1

Set culling mask for the cameras you do not want to show GUI. You can choose a camera and from culling mask set only the layers you want them to render.

Thanks. i totally forgot is option :)