I’m following the Space Shooter tutorial but I’m trying to change the script for the explosions to just collecting the Asteroid.
I have no errors in the script but the Asteroid does not disappear with it Collides with my spaceship and the score keeps adding points soon as an Asteroid comes into frame.
If anyone can provide me a hint on where I am wrong please do let me know!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Collect: MonoBehaviour
{
public int scoreValue;
private Done_GameController gameController;
void Start ()
{
GameObject gameControllerObject = GameObject.FindGameObjectWithTag ("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent <Done_GameController>();
}
if (gameController == null)
{
Debug.Log ("Cannot find 'GameController' script");
}
}
void OnTriggerEnter (Collider other)
{
//Check the provided Collider2D parameter other to see if it is tagged "PickUp", if it is...
if (other.gameObject.CompareTag("Enemy"))
//... then set the other object we just collided with to inactive.
other.gameObject.SetActive(false);
gameController.AddScore(scoreValue);
//Add one to the current value of our count variable.
}
}