Hello!
I’m having a problem while trying to access a variable that I have declared in another script. The problem is, that I’m need to check this variable from the object that I hit, BUT unity is telling me that this variable doesn’t exist (I was thinking to look this variable through the collider, but it isn’t working).
Here’s my class that is attached on the object that will be hit:
public class CapsuleLoad : MonoBehaviour {
public int bulletsNo;
void Start () {
if (bulletsNo == 0)
bulletsNo = 1;
}
}
`
And this is the code that I was thinking to use:
void OnTriggerEnter (Collider colliderObject){
if (colliderObject.GetComponent("CapsuleLoad")){
int currentBullets = colliderObject.GetComponent("CapsuleLoad").bulletsNo;
Destroy(colliderObject.gameObject);
}
The exact error that I'm getting is: Type 'UnityEngine.Component' does not contain a definition for 'bulletsNo' and no extension method 'bulletsNo' of type 'UnityEngine.Component' could be found (are you missing a using directive or an assembly reference?);
(Yes, I'm using C#)
`