- Home /
Question by
PrisVas · Apr 18, 2014 at 01:26 AM ·
null referencetransform.parent
transform.parent == null not working
I really dont know what is happenning, so, here is the code and the console return:
void OnTriggerStay(Collider other)
{
if (Input.touchCount == 0 && (transform.parent == null || transform.parent.Equals(null)))
{
print(other.name);
if (other.tag == "CasaLivre")
{
print("Entrei");
transform.parent = other.transform;
print("O pai inicio"+transform.parent);
if (transform.name == "cannon(Clone)")
{
transform.position = other.transform.position + other.transform.right * 1.3f;
transform.position = new Vector3(transform.position.x, 1f, transform.position.z);
other.transform.tag = "CasaOcupadaCan";
}
else if (transform.name == "catapult1(Clone)" || transform.name == "catapult2(Clone)")
{
transform.position = other.transform.position + other.transform.right * 1.3f - other.transform.forward * 1.3f;
other.transform.tag = "CasaOcupadaCat";
}
else
{
transform.position = new Vector3(other.transform.position.x, transform.position.y, other.transform.position.z);
other.transform.tag = "CasaOcupada";
}
GameObject.Find("Tabuleiro").GetComponent<PositioninScript>().posicionados += 1;
VerificaGiratorio();
}
else
{
if (transform.parent == null)
{
print("Sai");
transform.position = posInicial;
transform.parent = null;
}
}
print("O pai fim" + transform.parent);
}
}
It's like the null is being ignored.
Please, give me some help.
Comment
Answer by MakeCodeNow · Apr 18, 2014 at 02:30 AM
I think you want transform.parent != null in your else block.