help
To access another script you need to create a reference and then access it.
You need to put your script on a gameobject. Probably the case if you use a trigger.
You should use a tag to access the GameObject as it’s faster than find.
In your second script add this:
1stScriptName variableName;
void Awake(){
variableName = GameObject.FindGameObjectWithTag("yourfirstscriptwithGameObjectTagName").GetComponent<1stscriptname>();
}
void Update () {
if(variableName.egeg) // you don't need this == true
InvokeRepeating("goo", 1 , 1);
}
I didn’t try the code, so I don’t if there are any typos.
If you use two different script, you cannot access the variable if you don’t point to the correct script.
Hope this help.
Stop posting duplicate threads please.
{
public Transform Target1;
public Rigidbody CubePrefab;
OnTrigAnim bup;
void Awake ()
{
bup = gameObject.FindGameObjectWithTag("OnTrigAnimPlayer").GetComponent<OnTrigAnim>();
}
void Update ()
{
if(variableName.egeg)
InvokeRepeating("goo", 1 , 1);
}
void goo ()
{
Rigidbody cubefire;
cubefire = Instantiate(CubePrefab) as Rigidbody;
cubefire.AddForce(Target1.forward * 10);
}
}
still errors thought any way it can be fixed like the ontriganim?
this is not bup = gameObject.
Plese look at the script I posted.
You need to use bup = GameObject.FindGameObjectWithTag
And you should try to name your variable correctly, as it will bite you when you have a more complex project.
This is good habits to have right at the start.