Connecting my 2 Scripts

Hey everyone so today I wrote 2 script:
Script A is a script that makes an object move to it’s target.(sits on the enemy player)
Script B is a script that spawns 3 different types of prefabs on different spawn points. These objects only stay on there positions for a couple of seconds and if it’s gone go to the new object at it’s new location. (this script sits on my itemSpawner with emtyGameobjects as spawnpoints).

Script A:


Script B:

The problem that I’m facing now is I wan’t to connect these 2 scripts.
The goal is to move my enemy with script A to the random spawned and random kind of object with script B.

if you know a solution please let my know. Thanks already!

1 Answer

1

Try this: If they’re in the same GameObject, you can use
ScriptName scriptVariable = GetComponent<ScriptName>(), otherwise you can use ScriptName scriptVariable = GameObject.Find("gameObjectName").GetComponent<ScriptName>()
then you can use the scriptVariable to access whatever ScriptName is.