- Home /
Question by
Chessnutter · Dec 26, 2017 at 11:16 PM ·
scripting problemerrorvariablebeginnerparent
X is a variable but a type was expected
Hello!
I have been stuck on this for 2 days, if you could help me I would be so grateful. I want to check if the parent of the collided object is named Asteroids, and if it is print finally to the console. The code below returns:
Assets/Scripts/LasarMovement.cs(19,39): error CS0118: Asteroids' is a
type' but a `variable' was expected
void OnTriggerEnter2D(Collider2D other) {
Debug.Log(other);
if (other.transform.parent == Asteroids) {
Debug.Log("finally!!!!!!!!!!!!!!!!!!");
}
}
Comment
Answer by ShadyProductions · Dec 26, 2017 at 11:53 PM
if (other.transform.parent.name == "Asteroids") {
look on the name property of the parent object.
??? look at the code I added in the answer
I tried that and it didn't work sorry, but I realised I forgot to declare the variable beforehand I am an idiot. Thanks for your time :)