Cannot Destroy Randomly Generated Object
I made a randomly generated maze using an algorithm i found in a Cat Like Coding tutorial. I want to destroy and have a score count of the destroyed objects that are randomly generated but my player just walks through them. I have the trigger on and everything. I tried attaching the code to the object itself and also to the code that randomly generates the maze. Nothing works. This is the code I attached to the Object:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class Collectible : MazePassage { public GameObject scoreText; public int theScore; public AudioSource collectSound;
void OnTriggerEnter(Collider other)
{
if (other.tag == "Coin")
{
collectSound.Play();
theScore += 5;
scoreText.GetComponent<Text>().text = "SCORE: " + theScore;
Destroy(other.gameObject);
}
}
And this is the part of the Maze code that generates the maze:
private void CreatePassage (MazeCell cell, MazeCell otherCell, MazeDirection direction) { MazePassage prefab = Random.value < collectibleProbability ? collectiblePrefab : passagePrefab ; MazePassage passage = Instantiate(prefab) as MazePassage; passage.Initialize(cell, otherCell, direction); passage = Instantiate(prefab) as MazePassage; passage.Initialize(otherCell, cell, direction.GetOpposite()); }
It also will not let me add the canvas or audio to the prefab. HELP!
Your answer
Follow this Question
Related Questions
Coroutines WaitForSeconds question... 3 Answers