Cannot access gameobject script using GetComponent

Hello everyone,

I am writing a simple script to access another GameObject’s script for enable and disable it using GetComponent but it seems that unity is not able detect that component.

The script that I am trying to access has this line at the start: namespace Oculus.Interaction. Actually, it is the PokeInteractable.cs script from the new Oculus Integration SDK, which is located into the BigRedButton GameObject.

I don’t know if GetComponent doesn’t work with that kind of scripts… but I don’t really know what is happening. Is there a way to access that component or anyone knows what can be wrong?

The line that I wrote is (where A_Button is the gameobject with the PokeInteractable script attached):

GameObject.FindGameObjectWithTag("A_Button").GetComponent<PokeInteractable>().enabled = true;

Thank you.

You should start by explaining what is going wrong when you try to do this. Is there a compile error? Is there an error at runtime?

95% chance you just failed to add using Oculus.Interaction; to your script.

2 Likes

Maybe it’s because of namespace, because your scripts need to be at the same place. I think you should remove namespace from your code.

1 Like

Hello,

First of all, thank you for your response. I am sorry for not being very clear about explaining my problem but YOU WERE RIGHT! adding using Oculus.Interaction to my script solved the problem.

Thank you so much.