Hi,
I have two seperate scripts one on an UI Button object and one on Main Camera. The latter script is a movement script which makes the camera orbit around a Game Object.
On Button, the first script is located in OnClick Event. How can I disable the Orbit Script via Button script using Getcomponent?
Thanks to all of you guys in advance. Peace.
To access a component of a gameobject you need to get the reference to that GameObject using tags and then enable/disable the component you want (in this case the Script).
In C# you do something like this :
public class Main : MonoBehaviour {
GameObject mainCamera;
void Start(){
// I assume you have the tag "MainCamera" on your camera gameobject
mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
}
//Call this function to disable the Orbit Script
void DisableScript(){
mainCamera.GetComponent<OrbitScript>().enable = false;
}
}