I am trying to create a script that allows the player to collect power ups. When the player collides with this powerup, I want a variable on a script attached to the powerup to turn to true (“Collected”). The rest of the code works fine, but on the “GetComponent” line I get the error is “The best overloaded method match for “UnityEngine.GetComponent(System.Type)” has some invalid arguments”. Anyone know what this means and how to fix it? Thank you in advance!
void OnTriggerEnter (Collider hit)
{
if(hit.gameObject.tag == "Weapon")
{
if(Inventory.Instance.HCisUnlocked == false)
{
Inventory.Instance.HCisUnlocked = true;
//Turn off the Collider
hit.collider.GetComponent(TheScript).Collected = true;
Debug.Log("Collected PowerUp");
}
if(Inventory.Instance.HCisUnlocked == true)
{
WeaponStates.Instance.HC.Ammo += AmmoBoost;
hit.collider.GetComponent(TheScript).Collected = true;
}
}
}