Hello,
Let me paint the scenario that I need some help with:
In my game I have three GameObjects which are prefabs. Each prefab has the usual stuff.
Prefab_badGuy has a mesh, rigidbody, etc and has a script called badGuy_AI.js
Prefab_badGuyBullet has all the same and has a script called badGuyBullet_AI.js
Prefab_player has all the same and has a script called Player.js.
In the Player.js script I have a function OnCollisionEnter(collision : Collision).
When I collide with either the instantiation of the Prefab_badGuy or Prefab_badGuyBullet a print (gameObject.name) prints out the gameObject name properly on the status line so collision is working properly.
Inside both the badGuy_AI.js and badGuyBullet_AI.js I have a variable declared ‘var Alliance : int;’.
I want to access this Alliance variable in the Player.js OnCollisionEnter(collision : Collision) when either the instantiation of the Prefab_badGuy or Prefab_badGuyBullet object collides with the player.
The syntax as I understand it is:
if (collision.gameObject.GetComponent(ScriptName).Alliance == 1) return;
But ‘ScriptName’ must be replaced with badGuy_AI.js or badGuyBullet_AI.js.
But I don’t know which object has collided with the player so I don’t know which .js to put into ScriptName.
How do I get around this???