Is my MonoDeveloped Glitchd ???
I know the title must explain the situation...
First I could do a loop in the start
Yesterday i was coding and i see this error saying that Object reference not set to an instance of an Object then i checked what it means(Im not english so...) Readed again and i thaught that was C# that didnt recognized my object so i did in the start method
> void Start () { Instantiate(edificio)
> //ignore here transform.position = new
> Vector3 (500,100,500);
} Pressed play and my pc lags so MUCH when i looked in the hierarchy more than 200 objects were cloned...
Sharing Integers and bools and Other stuff
So i wanted to make a camera like MOBA Stile But I also wanted that if a bool was true the camera (teleportates) to the object that is being atacked(once again bool checks that) But then One thing happened: The camera only goes 1000 x 500 of the terrain (Looks it is because of the screen) And then i tryed this code to see if this works:
public float goX ; public float goY ; public float goZ ; private float X; private float Y; private float Z; public int getVida; private int setVida; public bool atacado;//atacado means atacked void Start () { getVida = setVida; setVida = 100; goX = X; goY = Y; goX = Z; X = transform.position.x; Y = transform.position.y; Z = transform.position.z; } void Alerta1(){ if (atacado == true) { if (getVida != 0) { atacado = true; }else{ if (getVida == 0) { atacado = false; } } } } void Update () {
if (Input.GetKey ("a")) { setVida = setVida - 20; atacado = true; Alerta1 (); } else { if (getVida == 0) {//vida means life in portuguese Debug.Log ("MORRI");//dead ... DestroyObject (this); } } } }// i did put all the code to see were i was going tried to do it but this two problem appeared
Couldnt share Int or Bools or other ints
if(GameObject.Find("edificio").GetComponent<vidaEdificioScratch>().atacado == true){
setX = GameObject.Find ("edificio").GetComponent<vidaEdificioScratch> ().goX;
setY = GameObject.Find ("edificio").GetComponent<vidaEdificioScratch> ().goZ;
setZ = GameObject.Find ("edificio").GetComponent<vidaEdificioScratch> ().goY;
}
and then this problem happens if (Input.GetKey ("a")) { setVida = setVida - 20; atacado = true; Alerta1 ();
it keeps doing the code without pressing the letter
Answer by Jessespike · Sep 08, 2016 at 04:58 PM
Hard to understand your question. What is the exact problem/error? If the variables goX, goZ, goY are public, then they should be accessible.
Are you sure the problem is not that setX and SetY are being set with Input.mousePosition at the start of each frame? I mean there's no use setting SetX, SetY, SetZ with GameObject.Find after the transform.position if Input.mousePosition sets them beforehand.
i maded that way to look more confusing if they entered the source of the game
Don't do that. This shouldn't even be a concern. Keep code easy to read and understandable, for your own sake and for other developers.
Hard to understand your question.
yeah is it because of my English or the text is too long and difficult to understand... but im going to topic to be more pleasant to read
Yesterday i was coding and i see this error saying that Object reference not set to an instance of an Object then i checked what it means(Im not english so...) Readed again and i thaught that was C# that didnt recognized my object so i did in the start method void Start () { Instantiate(edificio) //ignore here transform.position = new Vector3 (500,100,500);First I could do a loop in the start
} Pressed play and my pc lags so $$anonymous$$UCH when i looked in the hierarchy more than 200 objects were cloned...
So i wanted to make a camera like $$anonymous$$OBA Stile But I also wanted that if a bool was true the camera (teleportates) to the object that is being atacked(once again bool checks that) But then One thing happened: The camera only goes 1000 x 500 of the terrain (Looks it is because of the screen) And then i tryed this code to see if this works: // a posiçao para onde ir public float goX ; public float goY ; public float goZ ; //Privado so pode mexer isto private float X; private float Y; private float Z;Sharing Integers and bools and Other stuff
//vida do edificio public int getVida; private int setVida; //a ser atacado ou n public bool atacado;//atacado means atacked
void Start () {
getVida = setVida; setVida = 100; goX = X; goY = Y; goX = Z; X = transform.position.x; Y = transform.position.y; Z = transform.position.z; } void Alerta1(){ if (atacado == true) { if (getVida != 0) { atacado = true; }else{ if (getVida == 0) { atacado = false;
} } } }
void Update () {
if (Input.Get$$anonymous$$ey ("a")) { setVida = setVida - 20; atacado = true; Alerta1 (); } else { if (getVida == 0) {//vida means life in portuguese Debug.Log ("$$anonymous$$ORRI");//dead ... DestroyObject (this);
} } }
}// i did put all the code to see were i was going tried to do it but this two problem appeared
Couldnt share Int or Bools or other ints
if(GameObject.Find("edificio").GetComponent<vidaEdificioScratch>().atacado == true){
setX = GameObject.Find ("edificio").GetComponent<vidaEdificioScratch> ().goX;
setY = GameObject.Find ("edificio").GetComponent<vidaEdificioScratch> ().goZ;
setZ = GameObject.Find ("edificio").GetComponent<vidaEdificioScratch> ().goY;
}
it keeps doing the code without pressing the letterand then this problem happens
if (Input.Get$$anonymous$$ey ("a")) { setVida = setVida - 20; atacado = true; Alerta1 ();
Your answer
![](https://koobas.hobune.stream/wayback/20220612092409im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to rotate camera diagonally over players shoulder while still facing towards players direction 0 Answers
3d camera not working as I want it to 0 Answers
Smooth camera movement and lookAt [solved] 0 Answers
First person camera snaps when switching cameras 0 Answers
Boolean variable is never true, even if declared true or ticked in the inspector 1 Answer