Hi,
I try to write clearer.
If I click a “button”, then I would like to disable “drag_mouse” script on all object.
(button = second in the upper menu)
I got this console message:
NullReferenceException: Object reference not set to an instance of an object
measure.OnGUI () (at Assets/script/FINAL/measure.cs:107)
I have made a screen-record from the problem:
http://www.csongorfekete.com/Unity_web_player/Unity_foreach_bug_V1.mov
This is my project, not on the final server, therefore screenshot function isn’t working:
http://www.csongorfekete.com/Unity_web_player/Terberendezo_v1.html
- user: a
- pass: a
- Push Z button, then you can see debug-consol in web player
This is the script:
using UnityEngine;
using System.Collections;
public class measure : MonoBehaviour {
public GUIStyle meres;
public GUIStyle merestooltip;
public GUIStyle szoveg;
public GUIStyle szovegapro;
public Camera cam1;
public Camera cam2;
private string szelesseg = "";
private string hosszusag = "";
public Texture2D cursorTexture;
public Vector2 mouse = Vector2.zero;
int counterAT=0;
int cursorSizeX=50;
int cursorSizeY=50;
void OnGUI () {
if (counterAT==2)
{
counterAT = counterAT-2;
cam1.enabled = true;
cam2.enabled = false;
// GameObject myCube = GameObject.FindGameObjectWithTag("Player");
// myCube.GetComponent<tooltip>().enabled = true;
}
if (GUI.Button (new Rect (Screen.width/2-205, 10, 50, 50), "" ,meres))
{
counterAT++;
Debug.Log(counterAT);
}
if (counterAT == 1)
{
GUI.Box (new Rect (20, 80, 120, 180), "" ,merestooltip);
GUI.Label(new Rect(40, 100, 60, 25), "TÁVOLSÁG\n" +
"MÉRÉS\n\n" +
"Szélesség (m)\n\n\n" +
"Hosszúság (m)" ,szoveg);
szelesseg = GUI.TextField (new Rect (40, 163, 60, 20), szelesseg, 4);
hosszusag = GUI.TextField (new Rect (40, 208, 60, 20), hosszusag, 4);
mouse = new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y);
GUI.DrawTexture(new Rect(mouse.x - (cursorSizeX / 2), mouse.y - (cursorSizeY / 2), cursorSizeX, cursorSizeY), cursorTexture);
cam1.enabled = false;
cam2.enabled = true;
GUI.Button(new Rect(40, 240, 100, 20), new GUIContent("További funkciók...", "Pontosabb mérési\n" +
"adatokat kaphat,\n" +
"ha használja:\n\n" +
"Q = nagyítás\n" +
"W = kicsinyítés\n" +
"Jobb egér =\n" +
"terület mozgatás"), szovegapro);
GUI.Label(new Rect(40, 270, 100, 60), GUI.tooltip , szovegapro);
// MÉRÉSI TARTOMÁNY
// MEASURE SECTION
if (Input.GetMouseButton(0))
{
szelesseg = mouse.x.ToString();
hosszusag = mouse.y.ToString();
// NOT FINISHED!
foreach(GameObject gameObj in GameObject.FindGameObjectsWithTag("Player"))
{
gameObj.GetComponent<drag_mouse>().enabled = false;
}
// break;
// cursorPoint++;
// Debug.Log(cursorPoint);
// Instantiate(cursorTexture);
}
}
}
}
I hope you could help me.
Thanks.