0

I am new to programming and i dont know how to fix this

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PickupSystem : MonoBehaviour
{
// Start is called before the first frame update

int pickupAmount;

 void OnCollisionEnter2D(Collision2D other)
{
    if(other.collider.name=="Player" )
    {
        gameObject.GetComponent<PlayerStats>().pickupMoney(pickupAmount);
        pickupAmount = Random.Range(6, 32);
        Destroy(gameObject);
    }
}

}

I have the pickupMoney method in the playerstats script

Dreikh
  • 19
  • 3
  • Are you sure you want to use `gameObject.GetComponent()` and look for the `PlayerStats` component on this object itself and not maybe rather `other.GetComponent()` and look for the component on the (supposedly Player) object you collide with? – derHugo Sep 01 '21 at 13:33

0 Answers0