void OnTriggerEnter(Collider obj) { if (obj.gameObject.tag == "Player") { // Destroy the coin if it collides with the player Destroy(this.gameObject); // Get the script attached to Main Player this.generateCoinsScript = obj.GetComponent <GenerateCoins>(); // Modify variables of the Main Player script this.generateCoinsScript.CoinsCount--; this.generateCoinsScript.CoinsPicked++; // Destroy all coins and theirs parent gameObject if not picked Destroy(this.gameObject.transform.parent.gameObject, 3f); } }
// Use this for initialization void Start() { this.coinsScript = GameObject.Find("Player").GetComponent <GenerateCoins>(); this.carScript = GameObject.Find("Player").GetComponent <Car>(); }