Hi everyone, I’m trying to make an if statement that checks if a gameobject’s doesn’t equal a specific tag.But the if statement isn’t working and the code is executed.Any idea what is wrong?
public bool somebool = false;
void Update(){
RaycastHit hit;
if(Physics.SphereCast(gameobject.transform.position, 1f, gameObject.transform.forward, out hit, 50)){
if(gameObject.tag != "SomeTag"){
somebool = true;
}
}
}
I think what you want is this:
public bool somebool = false;
void Update(){
RaycastHit hit;
if(Physics.SphereCast(gameobject.transform.position, 1f, gameObject.transform.forward, out hit, 50)){
if(hit.collider.tag != "SomeTag"){
somebool = true;
}
}
}
You should try using gameObject.CompareTag().
public bool somebool = false;
void Update(){
RaycastHit hit;
if(Physics.SphereCast(gameobject.transform.position, 1f, gameObject.transform.forward, out hit, 50)){
if(!gameobject.CompareTag("SomeTag")){
somebool = true;
}
}
}
I hear it’s faster than the other way as well.
nevermind i’m a dumbo i didn’t assign the tag lmao